Latest 0.2.x
Arch linux 64-bit
Trying to build run time with Builder:
let mut rt = runtime::Builder::new().build().unwrap();
rt.block_on(async {})
Throws:
thread 'main' panicked at 'there is no reactor running, must be called from the context of Tokio runtime', src/libcore/option.rs:1188:5
Below works properly:
let mut rt = runtime::Runtime::new()?;
rt.block_on(async {})
By default, the runtime::Builder will create an empty "shell" runtime that doesn't actually do anything. In order to actually run futures, you will need to call Builder::threaded_scheduler or Builder::basic_scheduler to configure how the runtime will schedule futures, and probably Builder::enable_io and/or Builder::enable_time to enable the IO reactor and timer, respectively (you can also use Builder::enable_all to get both).
Constructing the same runtime returned by runtime::Runtime::new() using the builder would look something like this (assuming features = ["full"]):
let mut rt = runtime::Builder::new()
.threaded_scheduler()
.enable_all()
.build()
.unwrap();
// ...
You can also see here for details.
Oh, i see thanks for clarification :)
No problem, glad I could help!
Mind if I close this issue, or do you think there are any docs changes we could make to clear this up?
@hawkw IMHO this is good candidate for examples, as at the start i went through examples and could not find how to set it up. Then i jumped in to https://docs.rs/tokio/0.2.13/tokio/runtime/index.html#basic-scheduler docs, looking now i can see this note https://docs.rs/tokio/0.2.13/tokio/runtime/index.html#resource-drivers (at the bottom), may be better to move this note before actual config... or mention directly in each description (Threaded Scheduler and Basic Scheduler)...
It would be awesome if there were more hints from the error thread 'main' panicked at 'there is no reactor running, must be called from the context of Tokio runtime' that you need to do the .enable_all() to get it running.
Easy to miss this part and it doesn't ring a bell when you're new to Tokio :)
I ran into this error and had no clue that I needed to do enable_all(). It might help us Tokio beginners if we add the following hint to the there is no reactor running message:
Hint: If you have built the runtime with a Builder, try calling enable_all() to enable I/O and time drivers
Closing as duplicate of #2465.
Most helpful comment
It would be awesome if there were more hints from the error
thread 'main' panicked at 'there is no reactor running, must be called from the context of Tokio runtime'that you need to do the.enable_all()to get it running.Easy to miss this part and it doesn't ring a bell when you're new to Tokio :)