Add cli & lib crates
This commit is contained in:
24
cli/src/util.rs
Normal file
24
cli/src/util.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use std::sync::mpsc as std_mpsc;
|
||||
use tokio::sync::mpsc as tokio_mpsc;
|
||||
use tokio::task;
|
||||
|
||||
pub fn proxy_channel<T>(std_rx: std_mpsc::Receiver<T>) -> tokio_mpsc::Receiver<T>
|
||||
where
|
||||
T: 'static + Send + Sync,
|
||||
{
|
||||
let (tx, tokio_rx) = tokio_mpsc::channel(255);
|
||||
|
||||
task::spawn_blocking(move || loop {
|
||||
let msg = match std_rx.recv() {
|
||||
Ok(msg) => msg,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
match tx.blocking_send(msg) {
|
||||
Ok(_) => {}
|
||||
Err(_) => return,
|
||||
}
|
||||
});
|
||||
|
||||
tokio_rx
|
||||
}
|
||||
Reference in New Issue
Block a user