#async-generator #async #generator

async-gen

Async generator in stable rust using async/await

6 releases

0.2.3 Jul 9, 2023
0.2.2 Jun 24, 2023
0.1.1 Jun 21, 2023

#1926 in Asynchronous

Download history 71/week @ 2025-11-12 24/week @ 2025-11-19 218/week @ 2025-11-26 251/week @ 2025-12-03 251/week @ 2025-12-10 220/week @ 2025-12-17 91/week @ 2025-12-24 40/week @ 2025-12-31 94/week @ 2026-01-07 245/week @ 2026-01-14 201/week @ 2026-01-21 150/week @ 2026-01-28 561/week @ 2026-02-04 105/week @ 2026-02-11 41/week @ 2026-02-18 49/week @ 2026-02-25

772 downloads per month
Used in orch

MIT license

15KB
190 lines

This library provides a way to create asynchronous generator using the async/await feature in stable Rust.

Installation

Add it as a dependency to your Rust project by adding the following line to your Cargo.toml file:

[dependencies]
async-gen = "0.2"

Examples

use std::pin::pin;
use async_gen::{gen, GeneratorState};

#[tokio::main]
async fn main() {
    let g = gen! {
        yield 42;
        return "42"
    };
    let mut g = pin!(g);
    assert_eq!(g.resume().await, GeneratorState::Yielded(42));
    assert_eq!(g.resume().await, GeneratorState::Complete("42"));
}

Dependencies

~67KB