async-observe 0.1.1

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

use {
    futures_lite::future,
    std::{thread, time::Duration},
};

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

    // Perform computations in another thread
    thread::spawn(move || {
        for n in 1..10 {
            thread::sleep(Duration::from_secs(1));

            // Send a new value without blocking the thread.
            // If sending fails, it means the sender was dropped.
            // In that case stop the computation.
            if tx.send(n).is_err() {
                break;
            }
        }
    });

    // Print the initial value (0)
    let n = rx.observe(|n| *n);
    println!("{n}");

    future::block_on(async {
        // Print the value whenever it changes
        while let Ok(n) = rx.recv().await {
            println!("{n}");
        }
    });
}