13 releases (5 breaking)

0.6.2 Aug 3, 2024
0.6.0 Jun 15, 2024
0.5.1 Feb 16, 2024
0.1.2 May 30, 2023

#5 in #periodic

Download history 2/week @ 2024-07-22 190/week @ 2024-07-29 23/week @ 2024-08-05 1/week @ 2024-08-12 7/week @ 2024-09-16 23/week @ 2024-09-23 32/week @ 2024-09-30 8/week @ 2024-10-14

63 downloads per month
Used in spaghettinuum

ISC license

14KB
274 lines

This is a tool for managing asynchronous tasks.

For example, maybe you have some periodic background tasks, plus a couple web servers. Using a TaskManager you can group these and shut them down as a group, gracefully, and wait for them all to end.

Handles

  • Long tasks
  • Simple periodic tasks (fixed sleep between invocations)
  • Async streams
  • Ctrl+c shutdown

Use it like

let tm = TaskManager::new();
tm.attach_sigint({
    log2 = logger.clone();
    |e| log2.err("Error handling sigint", e)
});
let tm1 = tm.clone();
let log2 = logger.clone();
tm.task(async move {
    match tm1.if_alive(server).await {
        Some(r) => match r {
            Ok(_) => {} // Server exited normally
            Err(e) => {
                log.err("Server died with error", e);
            }
        },
        None => {} // Received shutdown
    };
});

tm.join().await;

Dependencies

~8–19MB
~262K SLoC