tokio-task-tracker
tokio-task-tracker is a simple graceful shutdown solution for tokio.
The basic idea is to use a TaskSpawner
to create TaskTracker
objects, and hold
on to them in spawned tasks. Inside the task, you can check tracker.cancelled().await
to wait for the task to be cancelled.
The TaskWaiter
can be used to wait for an interrupt and then wait for all
trackers to be dropped.
Example
use Duration;
async
If you do not wish to allow a task to be aborted, you still need to make sure the task captures the tracker:
// Start a task
spawner.spawn;
You can also create a tracker via the task
method:
// Start a task
let tracker = spawner.task;
spawn;
Trackers can be used to spawn subtasks via tracker.subtask()
or tracker.spawn()
.