How to implement a future for a long running function I can not modify?

Tokio uses cooperative multitasking based on the Futures model. But your goal was to avoid the cooperation and be able to perform blocking operations that can only be pre-empted by the OS. Therefore, you have to use OS-prempted threads, instead of Futures-preempted threads.

Even though Tokio has its own threadpool that could theoretically do blocking operations, it's explicitly not designed for that, and doing so would disrupt Tokio's operation.

If you want to block threads, get your own threads.

5 Likes