Skip to content

feature: http::HttpServer::handle_request() issues #110

@nick1udwig

Description

@nick1udwig

Is your feature request related to a problem? Please describe.
There are two big issues I'm running into with handle_request().

  1. I want to, as a result of handling either an HTTP or WS request, .ws_push_all_channels(). However, I can't since I'm in a closure inside of a HttpServer method call that is borrowing it as mutable.
  2. I have some state I want to be able to use as a mutable reference in both the HTTP and the WS closure. But Rust complains:
          error[E0524]: two closures require unique access to `*message_archive` at the same time
          --> foo/src/lib.rs:145:9
           |
       74  |     server.handle_request(
           |            -------------- first borrow later used by call
       75  |         request,
       76  |         |request| {
           |         --------- first closure is constructed here
       ...
       124 |                         message_archive,
           |                         --------------- first borrow occurs due to use of `*message_archive` in closure
       ...
       145 |         |_channel, _message_type, blob| {
           |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ second closure is constructed here
       ...
       151 |                 message_archive,
           |                 --------------- second borrow occurs due to use of `*message_archive` in closure
    

Describe the solution you'd like

  1. One possible way around this would be to expose the ws_channels HashMap and add a function (not a method) ws_push_all_channels() that operated on the given HashMap.
  2. idk

Describe alternatives you've considered
What I'm probably going to have to do is go back to the old pattern of matching.

Notes
It seems like we probably didn't hit the second of these problems before because we used WS only one way (i.e. Kinode -> FE or FE -> Kinode, not both), and hence, the state need not be passed into two closures, only one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions