unblock returns Task

This commit is contained in:
Zhixing Zhang 2022-03-05 16:49:25 -08:00
parent 2bb7954464
commit 176c6605d9
No known key found for this signature in database
GPG Key ID: A9B39B854E6A107F
1 changed files with 4 additions and 3 deletions

View File

@ -92,8 +92,9 @@ use std::task::{Context, Poll};
use std::thread;
use std::time::Duration;
pub use async_task::Task;
use async_channel::{bounded, Receiver};
use async_task::{Runnable, Task};
use async_task::Runnable;
use atomic_waker::AtomicWaker;
use futures_lite::{future, prelude::*, ready};
use once_cell::sync::Lazy;
@ -267,12 +268,12 @@ impl Executor {
/// let out = unblock(|| Command::new("dir").output()).await?;
/// # std::io::Result::Ok(()) });
/// ```
pub async fn unblock<T, F>(f: F) -> T
pub fn unblock<T, F>(f: F) -> Task<T>
where
F: FnOnce() -> T + Send + 'static,
T: Send + 'static,
{
Executor::spawn(async move { f() }).await
Executor::spawn(async move { f() })
}
/// Runs blocking I/O on a thread pool.