smol-rs / async-compat

Compatibility adapter between tokio and futures
Apache License 2.0
156 stars 12 forks source link

Compat with tokio::spawn #15

Open jon-chuang opened 2 years ago

jon-chuang commented 2 years ago

It would be very cool if a Compat could be produced for consuming the Spawner in the Tokio Handler so that the non-tokio runtime can spawn Tokio tasks.

The way I'm thinking to do it is to first, have the background thread do a sleep(u64::MAX) so that it can never process any spawned tasks.

Then, we hijack the Spawner from the handler (currently impossible as spawner field along with other needed data types are pub(crate)) and process tasks from it by putting them onto the current runtime's task queue.

inevity commented 2 years ago

When case do you mean: futures::executor::block_on or tokio::main/tokio::block_on? Give an example?