Updated 'src/async/streams.md'.

This commit is contained in:
Hector PENG
2026-04-12 11:14:38 +08:00
parent fa5fa2c297
commit 33574b036d
3 changed files with 52 additions and 440 deletions

View File

@@ -0,0 +1,7 @@
[package]
name = "stream_demo"
version = "0.1.0"
edition = "2024"
[dependencies]
trpl = "0.3.0"

View File

@@ -0,0 +1,17 @@
use trpl::StreamExt;
use std::time::Duration;
fn main() {
let fut = async {
let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let iter = values.iter().map(|n| n * 2);
let mut stream = trpl::stream_from_iter(iter);
while let Some(value) = stream.next().await {
println!("值为: {value}");
trpl::sleep(Duration::from_secs(1)).await;
}
};
trpl::block_on(fut)
}