Crates.io | async-gen |
lib.rs | async-gen |
version | 0.2.3 |
source | src |
created_at | 2023-06-20 15:33:29.814308 |
updated_at | 2023-07-09 18:20:43.36624 |
description | Async generator in stable rust using async/await |
homepage | |
repository | https://github.com/nurmohammed840/async-gen |
max_upload_size | |
id | 895290 |
size | 15,505 |
This library provides a way to create asynchronous generator using the async/await
feature in stable Rust.
Add it as a dependency to your Rust project by adding the following line to your Cargo.toml
file:
[dependencies]
async-gen = "0.2"
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"));
}