25 lines
536 B
Rust
25 lines
536 B
Rust
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
|
|
}
|