#generator #async-await #stable #gen #async #features #yield

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

#926 in Asynchronous

Download history 54/week @ 2024-11-17 127/week @ 2024-11-24 207/week @ 2024-12-01 34/week @ 2024-12-08 125/week @ 2024-12-15 123/week @ 2024-12-22 65/week @ 2024-12-29 162/week @ 2025-01-05 71/week @ 2025-01-12 85/week @ 2025-01-19 39/week @ 2025-01-26 49/week @ 2025-02-02 56/week @ 2025-02-09 87/week @ 2025-02-16 64/week @ 2025-02-23 29/week @ 2025-03-02

241 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

~71KB