Currently if you run a current_thread::Executor, running spawn() from the futures run by that executor will fail with SpawnError { is_shutdown: true }. It would be nice if the error was clearer here about what's going wrong. (For more context see #377.)
Do I understand correctly that this means I can't call tokio::spawn before calling tokio::run?
This is correct. If you need to call tokio::spawn, you should wrap the init code w/ lazy and pass that to tokio::run. Something like:
tokio::run(future::lazy(|| {
tokio::spawn(my_task());
Ok(())
}))
I want to make this nicer in 0.2
Cool, that solved my problem for now.
The message is now: "must be called from the context of Tokio runtime"
Most helpful comment
This is correct. If you need to call
tokio::spawn, you should wrap the init code w/lazyand pass that totokio::run. Something like:I want to make this nicer in 0.2