book icon indicating copy to clipboard operation
book copied to clipboard

Enhancement(17.2 - Listing 17-11)

Open Andebugulin opened this issue 6 months ago • 0 comments

Listing 17-11 looks like this currently:

        let tx_fut = async {
            let vals = vec![
                String::from("hi"),
                String::from("from"),
                String::from("the"),
                String::from("future"),
            ];

            for val in vals {
                tx.send(val).unwrap();
                trpl::sleep(Duration::from_millis(500)).await;
            }
        };

        let rx_fut = async {
            while let Some(value) = rx.recv().await {
                println!("received '{value}'");
            }
        };

        trpl::join(tx_fut, rx_fut).await;

Confusion

Listing 17-11 lacks let (tx, mut rx) = trpl::channel(); in the beginning of the listing

Other Listings in the 17.2. chapter that relate to this code, they all have this line.

Suggestion

Add this line into the listing:

        let (tx, mut rx) = trpl::channel();

        let tx_fut = async {
            let vals = vec![
                String::from("hi"),
                String::from("from"),
                String::from("the"),
                String::from("future"),
            ];

            for val in vals {
                tx.send(val).unwrap();
                trpl::sleep(Duration::from_millis(500)).await;
            }
        };

        let rx_fut = async {
            while let Some(value) = rx.recv().await {
                println!("received '{value}'");
            }
        };

        trpl::join(tx_fut, rx_fut).await;

Andebugulin avatar Apr 14 '25 08:04 Andebugulin