#async-generator #async #generator

macro async-gen-macros

Async generator in stable rust using async/await

4 releases (2 breaking)

0.3.0 Jul 9, 2023
0.2.1 Jun 24, 2023
0.2.0 Jun 22, 2023
0.1.0 Jun 20, 2023

#12 in #async-generator

Download history 117/week @ 2025-10-17 79/week @ 2025-10-24 71/week @ 2025-10-31 106/week @ 2025-11-07 55/week @ 2025-11-14 104/week @ 2025-11-21 205/week @ 2025-11-28 261/week @ 2025-12-05 245/week @ 2025-12-12 197/week @ 2025-12-19 66/week @ 2025-12-26 58/week @ 2026-01-02 108/week @ 2026-01-09 295/week @ 2026-01-16 195/week @ 2026-01-23 109/week @ 2026-01-30

719 downloads per month
Used in 2 crates (via async-gen)

MIT license

5KB
106 lines

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

It is similar to async-stream, But closely mimics the Coroutine API, Allowing the generator also return a value upon completion, in addition to yielding intermediate values.

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"));
}

No runtime deps