How to save different type of Futures?

I read the tutorial write by Tokio about Futures, and in the example it save Futures like this:

type Task = Pin<Box<dyn Future<Output = ()> + Send>>;

struct MiniTokio {
    tasks: VecDeque<Task>,
}

I think they write this to make the example simple, but I wondered in the real case, the Output can be any type, so how do people save these futures if they are writing an executor?

You can define a trait that you implement on any future, and which doesn't have the output be part of the trait. When it completes, the trait would write the result to some other memory location (e.g. send it to the JoinHandle object) rather than returning it from the function.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.