Skip to content

Commit f6898e4

Browse files
committed
init blocking-updates
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
1 parent 9c32133 commit f6898e4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/task/blocking.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ fn schedule(t: async_task::Task<Tag>) {
9696
/// Spawns a blocking task.
9797
///
9898
/// The task will be spawned onto a thread pool specifically dedicated to blocking tasks.
99-
pub(crate) fn spawn<F, R>(future: F) -> JoinHandle<R>
99+
pub(crate) fn spawn<F, R>(f: F) -> JoinHandle<R>
100100
where
101-
F: Future<Output = R> + Send + 'static,
101+
F: FnOnce() -> R + Send + 'static,
102102
R: Send + 'static,
103103
{
104104
let tag = Tag::new(None);
105+
let future = async move { f() };
105106
let (task, handle) = async_task::spawn(future, schedule, tag);
106107
task.schedule();
107108
JoinHandle::new(handle)

src/task/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub(crate) mod blocking;
6868
/// #
6969
/// use async_std::task;
7070
///
71-
/// task::blocking(async {
71+
/// task::blocking(|| {
7272
/// println!("long-running task here");
7373
/// }).await;
7474
/// #
@@ -79,10 +79,10 @@ pub(crate) mod blocking;
7979
#[cfg(any(feature = "unstable", feature = "docs"))]
8080
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
8181
#[inline]
82-
pub fn blocking<F, R>(future: F) -> task::JoinHandle<R>
82+
pub fn blocking<F, R>(f: F) -> task::JoinHandle<R>
8383
where
84-
F: crate::future::Future<Output = R> + Send + 'static,
84+
F: FnOnce() -> R + Send + 'static,
8585
R: Send + 'static,
8686
{
87-
blocking::spawn(future)
87+
blocking::spawn_blocking(future)
8888
}

0 commit comments

Comments
 (0)