Draft auto-update process for comet in devtools
This commit is contained in:
parent
a105ad4f9f
commit
267583c2a9
6 changed files with 250 additions and 107 deletions
|
|
@ -1,4 +1,6 @@
|
|||
use crate::futures::futures::channel::mpsc;
|
||||
use crate::futures::futures::channel::oneshot;
|
||||
use crate::futures::futures::stream::{self, StreamExt};
|
||||
use crate::runtime::Task;
|
||||
|
||||
use std::thread;
|
||||
|
|
@ -17,3 +19,25 @@ where
|
|||
|
||||
Task::stream(receiver)
|
||||
}
|
||||
|
||||
pub fn try_spawn_blocking<T, E>(
|
||||
f: impl FnOnce(mpsc::Sender<T>) -> Result<(), E> + Send + 'static,
|
||||
) -> Task<Result<T, E>>
|
||||
where
|
||||
T: Send + 'static,
|
||||
E: Send + 'static,
|
||||
{
|
||||
let (sender, receiver) = mpsc::channel(1);
|
||||
let (error_sender, error_receiver) = oneshot::channel();
|
||||
|
||||
let _ = thread::spawn(move || {
|
||||
if let Err(error) = f(sender) {
|
||||
let _ = error_sender.send(Err(error));
|
||||
}
|
||||
});
|
||||
|
||||
Task::stream(stream::select(
|
||||
receiver.map(Ok),
|
||||
stream::once(error_receiver).filter_map(async |result| result.ok()),
|
||||
))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue