Closed George3d6 closed 6 years ago
current_thread::spawn
requires a 'static
bound. This is because there is no guarantee that the stack stays around.
In your example, it looks like you can add some move
statements to your callbacks to move status_map
into the inner closure, then it should work.
I have the following code:
Which refuses to compile with the error
status_map does not live long enough
Seeing as status_map is declared in the outermost scope and the server is multithreaded, why would this happen ? Is there a way to achieve what I'm trying (accessing a variable declared inside main from inside the Future object).