mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
606 B
27 lines
606 B
extern crate trpl; // required for mdbook test
|
|
|
|
// ANCHOR: all
|
|
use trpl::{ReceiverStream, Stream, StreamExt};
|
|
|
|
fn main() {
|
|
trpl::run(async {
|
|
let mut messages = get_messages();
|
|
|
|
while let Some(message) = messages.next().await {
|
|
println!("{message}");
|
|
}
|
|
});
|
|
}
|
|
|
|
fn get_messages() -> impl Stream<Item = String> {
|
|
let (tx, rx) = trpl::channel();
|
|
|
|
let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
|
|
for message in messages {
|
|
tx.send(format!("Message: '{message}'")).unwrap();
|
|
}
|
|
|
|
ReceiverStream::new(rx)
|
|
}
|
|
// ANCHOR_END: all
|