#tokio #async #channels #mpsc

tokio-non-async

Helpers for dealing with tokio channels in non-async code

3 releases

0.1.2 Jul 20, 2020
0.1.1 Jul 18, 2020
0.1.0 Jul 18, 2020

#316 in Asynchronous

Download history 25/week @ 2020-11-07 17/week @ 2020-11-14 25/week @ 2020-11-21 16/week @ 2020-11-28 17/week @ 2020-12-05 32/week @ 2020-12-12 28/week @ 2020-12-19 22/week @ 2020-12-26 12/week @ 2021-01-02 22/week @ 2021-01-09 19/week @ 2021-01-16 11/week @ 2021-01-23 3/week @ 2021-02-06 10/week @ 2021-02-13 4/week @ 2021-02-20

85 downloads per month

Custom license

5KB
81 lines

Helpers for dealing with tokio channels from non-async code in a blocking manner

let (mut tx, mut rx) = mpsc::channel(10);

for i in 0i32..10 {
    tx.send(i).await.unwrap();
}

drop(tx);

tokio::task::spawn_blocking(move || {
    while let Some(received) = rx.optimistic_blocking_recv() {
        let received = rx.optimistic_blocking_recv();
        some_blocking_op(received);
    }
})
.await
.unwrap();

Dependencies

~2.5MB
~42K SLoC