pykeio / async-stream-lite

Proc macro-free async/await Rust streams
https://docs.rs/async-stream-lite
Other
1 stars 0 forks source link
async-stream rust rust-async

async-stream-lite

It's async-stream, but without proc macros.

use async_stream_lite::async_stream;

use futures_util::{pin_mut, stream::StreamExt};

#[tokio::main]
async fn main() {
    let stream = async_stream(|r#yield| async move {
        for i in 0..3 {
            r#yield(i).await;
        }
    });
    pin_mut!(stream);
    while let Some(value) = stream.next().await {
        println!("got {}", value);
    }
}

#![no_std] support

async-stream-lite supports #![no_std] on nightly Rust (due to the usage of the unstable #[thread_local] attribute). To enable #![no_std] support, enable the unstable-thread-local feature.