mio_channel

Crates.iomio_channel
lib.rsmio_channel
version0.1.3
sourcesrc
created_at2022-11-11 12:54:22.505539
updated_at2022-11-11 13:34:53.007931
descriptionProvide a wrapper of the standard channel that can be polled with Mio.
homepage
repositoryhttps://github.com/oh-jinsu/mio_channel
max_upload_size
id712835
size7,155
오진수 (oh-jinsu)

documentation

https://docs.rs/mio_channel

README

mio_channel

Provide a wrapper of the standard channel that can be polled with Mio.

Example

const CHANNEL: mio::Token = mio::Token(0);

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut poll = mio::Poll::new()?;

    let mut events = mio::Events::with_capacity(2);

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

    poll.registry().register(&mut rx, CHANNEL, mio::Interest::READABLE)?;

    let handler = std::thread::spawn(move || {
        std::thread::sleep(std::time::Duration::from_millis(1000));

        let _ = tx.send("Hello world!");
    });

    poll.poll(&mut events, None)?;

    assert_eq!(rx.try_recv()?, "Hello world!");

    let _ = handler.join();

    Ok(())
}
Commit count: 7

cargo fmt