mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-19 04:33:27 +08:00
Updated 'src/async/streams.md'.
This commit is contained in:
7
projects/stream_demo/Cargo.toml
Normal file
7
projects/stream_demo/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "stream_demo"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
trpl = "0.3.0"
|
||||
17
projects/stream_demo/src/main.rs
Normal file
17
projects/stream_demo/src/main.rs
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user