tokio::Runtime abort all orphaned tasks?

Let us define an 'orphaned task' as a task we create via tokio::spawn but we never store the JoinHandle.

Given a tokio Runtime, is there a way to abort all 'orphaned tasks' ?

That happens when the runtime shuts down. There aren't any other mechanisms for doing it.

Maybe refactoring your code to use task groups from the task-group crate would let you achieve your goal?

1 Like

Not a direct answer, but recently I've also been asking myself about how can I make code using tasks well-behaved, didn't found a satisfactory solution, but than figured out that I can just use tokio::join! / tokio::select! instead, as confining all async to a single task/thread simplifies things a bunch!

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.