tokio-rs / tokio-compat

Streamline updating a Tokio 0.1 application to Tokio 0.2.
MIT License
51 stars 15 forks source link

tokio::task::block_in_place can only be called inside spawned tasks #19

Open Marwes opened 4 years ago

Marwes commented 4 years ago

The following panics

#[test]
fn block_on_from_block_on() {
    let mut rt = runtime::Runtime::new().unwrap();
    rt.block_on_std(async {
        tokio_02::task::block_in_place(move || ());
    });
}

Easy workaround by wrapping the bblock_in_place call with a tokio::spawn, but it had me confused for a bit.

hawkw commented 4 years ago

Yeah, this is a Tokio 0.2 limitation — there is an upstream ticket about it: https://github.com/tokio-rs/tokio/issues/1838. As per https://github.com/tokio-rs/tokio/issues/1838#issuecomment-564216581, this limitation may be removed in the future.