Skip to content

feat: Add async LazyLock implementation - #168

Draft
mhambre wants to merge 2 commits into
apache:mainfrom
mhambre:feat/async-lazylock
Draft

feat: Add async LazyLock implementation#168
mhambre wants to merge 2 commits into
apache:mainfrom
mhambre:feat/async-lazylock

Conversation

@mhambre

@mhambre mhambre commented Aug 21, 2026

Copy link
Copy Markdown

Adds support for an asynchronousLazyLock inspired by async-lazy and similarly the API provided by std::sync::LazyLock.

The main addition to this is the fallible initialization through LazyLock::try_force and being runtime agnostic (async-lazy is married to Tokio through sync primitives) by using asyncband's Mutex and OnceCell.

Some design choices:

  • Cancelled futures restart rather than continuing polling from the cancellation point. This choice is subject to discussion and could also be implemented in the future if decided.
  • Panics in the initializer poison the lock.
  • Keeping with the API of std::sync::LazyLock, get methods are introspective, force methods actively perform initialization.
  • Deref traits aren't implemented because you can't await a deref.

This implementation is in reference to #160.

@tisonkun

Copy link
Copy Markdown
Member

Thanks for your contribution @mhambre! Feel free to ping me when this PR is ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants