async-observe 0.1.1

Async single-producer, multi-consumer channel that only retains the last sent value
Documentation
//! Stream observer example.

use futures_lite::{StreamExt, future};

fn main() {
    let (tx, rx) = async_observe::channel(0);

    let producer: _ = async move {
        //                  ^^^^
        // Move tx into the future so it is dropped after the loop ends.
        // Dropping the sender is important so the receiver can
        // see it and stop the stream.

        for n in 1..10 {
            future::yield_now().await;
            _ = tx.send(n);
        }
    };

    // Create a stream from the receiver
    let consumer = rx.into_stream().for_each(|n| println!("{n}"));

    future::block_on(future::zip(producer, consumer));
}