#generator #async #async-await #stable #gen

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

#61 in #gen

Download history 17/week @ 2024-10-14 8/week @ 2024-10-21 31/week @ 2024-11-04 15/week @ 2024-11-11 61/week @ 2024-11-18 151/week @ 2024-11-25 190/week @ 2024-12-02 43/week @ 2024-12-09 115/week @ 2024-12-16 144/week @ 2024-12-23 62/week @ 2024-12-30 158/week @ 2025-01-06 74/week @ 2025-01-13 76/week @ 2025-01-20 29/week @ 2025-01-27

356 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.

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