#generator #async #async-await #stable #gen #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

#1832 in Asynchronous

Download history 56/week @ 2024-07-01 16/week @ 2024-07-08 94/week @ 2024-07-15 224/week @ 2024-07-22 59/week @ 2024-07-29 31/week @ 2024-08-05 73/week @ 2024-08-12 28/week @ 2024-08-19 33/week @ 2024-08-26 59/week @ 2024-09-02 87/week @ 2024-09-09 25/week @ 2024-09-16 66/week @ 2024-09-23 70/week @ 2024-09-30 12/week @ 2024-10-07 14/week @ 2024-10-14

163 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

~70KB