async-local 0.7.0-beta.3

For safely extending the lifetime of thread locals
docs.rs failed to build async-local-0.7.0-beta.3
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: async-local-2.0.1

Async Local

License Cargo Documentation

Thread-safe pointers to thread-locals are possible

Traditionally the downside of thead-locals has been that usage is constrainted to the LocalKey::with closure with no lifetime escapement, the rationale being that anything beyond this is of an indeterminate lifetime. There is however a way around this limitation: by using a barrier to guard against thread local destruction until worker threads shutting down can rendezvous, no tasks will outlive thread local data belonging to any worker thread, and all pointers to thread locals created within an async context and held therein will be of a valid lifetime. Utilizing this barrier mechanism, this crate introduces AsyncLocal::with_async, the async counterpart of LocalKey::with, as well as the unsafe pointer types and safety considerations foundational for using thread local data within an async context and across await points.

Runtime Support

The only requirement for async runtimes to be compatible with async-local is that upon shutdown pending async tasks aren't dropped by thread local destructors.

Runtime Feature Flag Shutdown Behavior
Tokio tokio-runtime Tasks dropped during shutdown sequence
async-std async-std-runtime Tasks forgotten
smol Not Supported Tasks dropped by TLS destructors

See doomsday-clock for runtime shutdown safety tests.

Stable Usage

This crate conditionally makes use of the nightly only feature type_alias_impl_trait to allow AsyncLocal::with_async to be unboxed. To compile on stable the boxed feature flag can be used to downgrade async_t::async_trait to async_trait::async_trait.