init blocking-updates

Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
This commit is contained in:
Yoshua Wuyts 2019-10-09 22:03:28 +02:00
parent 23beab4125
commit 1a3429655c
No known key found for this signature in database
GPG key ID: 24EA8164F96777ED
2 changed files with 7 additions and 6 deletions

View file

@ -96,12 +96,13 @@ fn schedule(t: async_task::Task<Tag>) {
/// Spawns a blocking task.
///
/// The task will be spawned onto a thread pool specifically dedicated to blocking tasks.
pub(crate) fn spawn<F, R>(future: F) -> JoinHandle<R>
pub(crate) fn spawn<F, R>(f: F) -> JoinHandle<R>
where
F: Future<Output = R> + Send + 'static,
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
let tag = Tag::new(None);
let future = async move { f() };
let (task, handle) = async_task::spawn(future, schedule, tag);
task.schedule();
JoinHandle::new(handle)

View file

@ -73,7 +73,7 @@ cfg_if::cfg_if! {
/// #
/// use async_std::task;
///
/// task::blocking(async {
/// task::blocking(|| {
/// println!("long-running task here");
/// }).await;
/// #
@ -84,10 +84,10 @@ cfg_if::cfg_if! {
#[cfg(any(feature = "unstable", feature = "docs"))]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[inline]
pub fn blocking<F, R>(future: F) -> task::JoinHandle<R>
pub fn blocking<F, R>(f: F) -> task::JoinHandle<R>
where
F: crate::future::Future<Output = R> + Send + 'static,
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
blocking::spawn(future)
blocking::spawn_blocking(future)
}