Futures Orchestra

A Tokio task pool for running futures concurrently with queuing, labels and cancellation.

futures_orchestra is a Tokio-based pool for running futures with a cap on how many run at once. You create a FuturePoolManager with a concurrency limit, a queue capacity, a Tokio runtime handle and a name, then submit futures to it. Anything past the limit waits in a bounded queue until a slot frees up. A full queue pushes back on the submitter.

Plain tokio::spawn has no limit. A semaphore adds a limit but leaves the rest to you. The pool also handles the parts you would otherwise build by hand around them. Each submission returns a TaskHandle<R> that carries the task's ID, can request cancellation and can be awaited for a Result<R, PoolError>. A panic inside a task is reported as an error and does not take down the pool.

Tasks can carry string labels when you submit them. cancel_tasks_by_label cancels every active task with a matching label in one call. Cancellation is cooperative: the pool races each task against a cancellation signal. Shutdown comes in two modes. Graceful lets running tasks finish and starts nothing new from the queue, while ForcefulCancel cancels the running tasks as well.

You can register completion handlers that are called for every finished task with its outcome (success, panic, cancellation or another error). FuturePoolManager is Clone, so different parts of an application can share one pool.

FuturePoolManagerRlxd has the same API with relaxed start ordering: when the pool is idle it dispatches straight past the queue; otherwise it spreads work across several strictly ordered lanes. It is faster than the default pool at the cost of strict FIFO start order.

[dependencies]
futures_orchestra = "1"

Licensed under MPL-2.0. Source at https://github.com/excsn/futures_orchestra and API docs at https://docs.rs/futures_orchestra.