3 ms·
async event loops in Rust are invoked explicitly by the programmer as well.
by pitaj 3y ago
async event loops in Rust are invoked explicitly by the programmer as well.
- gavinhoward 3y agoAre they always invoked explicitly? Or is it sometimes implicit?
- pitaj 3y agoThe closest to implicit you can get is the `#[tokio::main]` attribute macro [1], which expands to something like this fn main() { tokio::runtime::Builder::new_multi_thread() .enable_all() .build() .unwrap() .block_on(async { println!("Hello world"); }) } [1]: https://docs.rs/tokio/latest/tokio/attr.main.html#using-the-multi-thread-runtime https://docs.rs/tokio/latest/tokio/attr.main.html#using-the-...
- saghm 3y agoThat's technically something the runtime implementation can choose, but for Tokio, the most common runtime, the sibling comment is correct that the only way to avoid having to explicitly define it is to use an annotation on the main function (which just generates the call to instantiate the runtime via a macro).
- saghm 3y agoThat's technically something the runtime implementation can choose, but for the most common runtime, Tokio,