Note: I also post this question in reddit and rust forum.
hi, I’m writing a TUI executable, I use tokio::select on crossterm::event::EventStream to achieve a non-blocking loop to receive user keyboard/mouse events.
At the same time, I also want to create an async task queue that can run some generic tasks: read/write files, update data logic, delay/timeout methods.
The word task here is similar to function pointers with a global context in C/C++.
After I read some documents, I found rust and tokio provide the tokio::task::JoinSet, it could help me create new async tasks, and run them in multiple green threads. And also possible to abort all the tasks, or wait for them done.
That’s probably what I want. But I still have 1 more question:
The JoinSet is not a future Stream, so I cannot use tokio::select on it. So how could I know what task is completed?
If I don’t select it, but keep create new tasks. Will it increase memory usage along with the tasks created, and finally get out of memory and crash the TUI application?
This question is answered by: https://users.rust-lang.org/t/do-i-need-to-clean-the-completed-tasks-in-tokio-joinset/117096/2?u=linrongbin16.
Just post here in case someone has the same issue.
1