Rust library for one-time async initialization

Related tags

Utilities async-lazy
Overview

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.

This crate offers an API similar to the Lazy type from async-once-cell crate. The difference is that this crate's Lazy accepts an FnOnce() -> impl Future instead of a Future, which makes use in statics easier.

Crate features

  • parking_lot: Enables the corresponding feature in tokio, and allows constructing Lazys in const contexts.
  • nightly: Uses nightly Rust features to implement IntoFuture for references to Lazys, obviating the need to call force().

Example

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

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

static LAZY : Lazy<u32> = Lazy::const_new(|| Box::pin(async { some_computation().await }));

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

    assert_eq!(result, 2);
}
You might also like...
Graceful shutdown util for Rust projects using the Tokio Async runtime.

Shutdown management for graceful shutdown of tokio applications. Guard creating and usage is lock-free and the crate only locks when: the shutdown sig

Async Rust cron scheduler running on Tokio.

Grizzly Cron Scheduler A simple and easy to use scheduler, built on top of Tokio, that allows you to schedule async tasks using cron expressions (with

Develop an async runtime like thing in Rust for educational purpose.

How-not-to-async-rs Develop an async runtime like thing in Rust for educational purpose. What this is not This is not going to be a blog post explaini

🦀 Rust library for printing human readable, relative time differences

🦀 Rust library for printing human readable, relative time differences

Async executor for WebAssembly

There are a number of async task executors available in Rust's ecosystem. However, most (if not all?) of them rely on primitives that might not be available or optimal for WebAssembly deployment at the time.

Mix async code with CPU-heavy thread pools using Tokio + Rayon

tokio-rayon Mix async code with CPU-heavy thread pools using Tokio + Rayon Resources Documentation crates.io TL;DR Sometimes, you're doing async stuff

Another Async IO Framework based on io_uring

kbio, the Async IO Framework based on io_uring, is used in KuiBaDB to implement async io. Features Support multi-threading concurrent task submission.

async-alloc-counter measures max allocations in a future invocation

async-alloc-counter measures max allocations in a future invocation see examples/ for usage This allocator can be used as follows: use async_alloc_cou

Async `TryFrom/TryInto` traits

async-convert Async TryFrom/TryInto traits API Docs | Releases | Contributing Installation $ cargo add async-convert Safety This crate uses #![deny(un

Owner
Jules Bertholet
University of Maryland class of 2024
Jules Bertholet
The feature-rich, portable async channel library

The feature-rich, portable async channel library > crates.io > docs.rs Why use Postage? Includes a rich set of channels. | barrier | broadcast | dispa

Austin Jones 221 Dec 26, 2022
Framework is a detector for different frameworks in one projects

Framework is a detector for different frameworks in one projects Usage use

Inherd OS Team (硬核开源小组) 3 Oct 24, 2022
Annotation to easily define ad-hoc / one-shot extension traits

Annotation to easily define ad-hoc / one-shot extension traits

Daniel Henry-Mantilla 2 Apr 19, 2022
Dr-dotnet - 🩺 One-click diagnosis of your dotnet applications. Works both locally or remotely as a web service

Dr-dotnet - ?? One-click diagnosis of your dotnet applications. Works both locally or remotely as a web service. Based on the lowest level dotnet profiling APIs and using the rust language ?? for a minimal runtime penalty.

Olivier Giniaux 25 Dec 17, 2022
Openfare - Monetize software with one commit.

OpenFare ?? Monetize software with one commit. ?? OpenFare monetizes any software library with one code change. The goal: fund the next million softwa

null 172 Dec 2, 2022
✨🥞The magic pancakes cli currently supports one command

✨ ?? Magic Pancakes The magic pancakes cli currently supports one command: $ pancakes generate Installing $ cargo build --release $ cargo install --pa

Kevin Rodríguez 3 May 6, 2022
1️⃣ el lisp number uno - one lisp to rule them all 🏆

luno el lisp number uno luno is the one lisp to rule them all. Still experimental, do not use it in production yet. goals embeddable small size simple

Eva Pace 3 Apr 25, 2022
One copy of Electron to rule them all.

chroma One copy of Electron to rule them all. chroma keeps a central, up-to-date version of Electron, and makes all your installed Electron apps use i

Gergő Móricz 12 Mar 20, 2023
Golang like WaitGroup implementation for sync/async Rust.

wg Golang like WaitGroup implementation for sync/async Rust.

Al Liu 8 Dec 6, 2022
single file, std only, async Rust executor

whorl - A single file, std only, async Rust executor whorl was created to teach you how async executors work in Rust. It is not the fastest executor n

Michael Gattozzi 459 Dec 29, 2022