async-lazy

Build Status Crates.io API reference License

An async version of once_cell::sync::Lazy, std::sync::OnceLock or lazy_static. Uses tokio's sychronization primitives.

Crate features

Example

```rust use std::time::Duration; use async_lazy::Lazy;

async fn somecomputation() -> u32 { tokio::time::sleep(Duration::fromsecs(1)).await; 1 + 1 }

static LAZY : Lazy = Lazy::constnew(|| Box::pin(async { somecomputation().await }));

[tokio::main]

async fn main() { let result = tokio::spawn(async { *LAZY.force().await }).await.unwrap();

assert_eq!(result, 2);

} ```