JoinSet
keeps the result of running a task to completion available until you use join_all
, join_next
, or try_join_next
to get the result of running a task. Memory usage will go up as long as this isn't done.
You have three directions you can go in:
- Use
tokio_util::TaskTracker
to track tasks. This is a lot likeJoinSet
, but it immediately drops the result of running a task, rather than keeping it around for later. - Use
tokio::select!
onJoinSet::join_next
as well asEventStream::next
, to pull out completed tasks. - Make use of
futures::stream::poll_fn
to turnJoinSet::poll_join_next
into a stream