Skip to content

Commit

Permalink
Ch. 17§05 initial edits on 'Composing Streams'
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskrycho committed Jul 11, 2024
1 parent 50de94b commit 4ec5706
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 431 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ fn main() {
while let Some(message) = messages.next().await {
println!("{message}");
}
})
});
}

fn get_messages() -> impl Stream<Item = String> {
let (tx, rx) = trpl::channel();

// ANCHOR: send
let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
for message in messages {
tx.send(format!("Message: '{message}'")).unwrap();
}
// ANCHOR_END: send

ReceiverStream::new(rx)
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
// ANCHOR: pin
// ANCHOR: timeout
use std::{pin::pin, time::Duration};
// --snip--

// ANCHOR_END: pin
use trpl::{ReceiverStream, Stream, StreamExt};

fn main() {
trpl::block_on(async {
// ANCHOR: pin
let mut messages =
pin!(get_messages().timeout(Duration::from_millis(200)));
// ANCHOR_END: pin

while let Some(result) = messages.next().await {
match result {
Expand All @@ -20,6 +15,7 @@ fn main() {
}
})
}
// ANCHOR_END: timeout

fn get_messages() -> impl Stream<Item = String> {
let (tx, rx) = trpl::channel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ fn main() {
})
}

// ANCHOR: messages
fn get_messages() -> impl Stream<Item = String> {
let (tx, rx) = trpl::channel();

// ANCHOR: messages
trpl::spawn_task(async move {
let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
for (index, message) in messages.into_iter().enumerate() {
Expand All @@ -29,7 +29,7 @@ fn get_messages() -> impl Stream<Item = String> {
tx.send(format!("Message: '{message}'")).unwrap();
}
});
// ANCHOR_END: messages

ReceiverStream::new(rx)
}
// ANCHOR_END: messages
17 changes: 0 additions & 17 deletions listings/ch17-async-await/listing-17-41/src/main.rs

This file was deleted.

292 changes: 0 additions & 292 deletions listings/ch17-async-await/listing-17-45/Cargo.lock

This file was deleted.

8 changes: 0 additions & 8 deletions listings/ch17-async-await/listing-17-45/Cargo.toml

This file was deleted.

Loading

0 comments on commit 4ec5706

Please sign in to comment.