Tokio::task vs futures::task

I would like to know what is the difference between tokio::task and futures::task.

Are both doing the same? If yes, which one should be preferred?

The tokio::task module contains utilities for spawning tasks on the Tokio runtime.

The futures::task is not really comparable to tokio::task. It is better to compare it to std::task, which mainly contains utilities for building wakers useful when manually implement the Future trait on your own types. It also has a Spawn trait, which I have never seen used.

You should use tokio::task if you want to spawn tasks on the Tokio runtime. You should use futures::task (or std::task) if you are manually implementing Future (or e.g. Stream) and need special wakers.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.