Running Rocket inside LocalSet does not work. #2819
-
Having this main:
and inside Structure struct:
When the "handle_request" function is called when a http req comes, rust panics with:
pointing to the line (in "add_request" function) that does "spawn_local". Essentially I am trying to run rocket inside of a LocalSet. I am pretty new to tokio and spawning in general so I am not sure exactly what is going on. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
After re-reading your comment - local set doesn't work in nested tasks. You need to create and await the local set in the request handler. Original: |
Beta Was this translation helpful? Give feedback.
After re-reading your comment - local set doesn't work in nested tasks. You need to create and await the local set in the request handler.
Original:
Rocket is
Send
, so you should justspawn
it with Tokio.spawn_local
is worse for performance, so you should only use it if you need to.