scoped-join-set 0.4.0

A scoped variant of tokio::task::JoinSet for spawning non-'static futures.
Documentation
scoped-join-set-0.4.0 has been yanked.

A scoped, lifetime-aware wrapper around [tokio::task::JoinSet].

ScopedJoinSet enables dynamically spawning async tasks whose futures are tied to a specific Rust lifetime 'scope. This provides a safe alternative to hand-managed unsafe approaches while enabling advanced async task orchestration where futures do not need to be 'static.

Each spawned task is split into:

  • A [FutureHolder], owning the actual boxed future and ensuring proper drop ordering.
  • A [WeakFuture] (inside the JoinSet), which the Tokio runtime polls.

When the [ScopedJoinSet] is dropped, all tasks are aborted and all future memory is reclaimed safely.

Guarantees

  • Futures spawned via [ScopedJoinSet::spawn] cannot outlive 'scope.
  • join_next() is cancellation-safe.
  • Dropping the entire set aborts all tasks.

Example

use scoped_join_set::ScopedJoinSet;

async fn demo<'a>() {
    let mut set = ScopedJoinSet::<u32>::new();

    set.spawn(async { 5 });

    while let Some(result) = set.join_next().await {
        assert_eq!(result.unwrap(), 5);
    }
}