File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ use kv_log_macro::trace;
1919/// Calling this function is similar to [spawning] a thread and immediately [joining] it, except an
2020/// asynchronous task will be spawned.
2121///
22+ /// See also: [`task::blocking`].
23+ ///
24+ /// [`task::blocking`]: fn.blocking.html
25+ ///
2226/// [spawning]: https://doc.rust-lang.org/std/thread/fn.spawn.html
2327/// [joining]: https://doc.rust-lang.org/std/thread/struct.JoinHandle.html#method.join
2428///
Original file line number Diff line number Diff line change @@ -51,7 +51,29 @@ pub(crate) mod blocking;
5151
5252/// Spawns a blocking task.
5353///
54- /// The task will be spawned onto a thread pool specifically dedicated to blocking tasks.
54+ /// The task will be spawned onto a thread pool specifically dedicated to blocking tasks. This
55+ /// is useful to prevent long-running synchronous operations from blocking the main futures
56+ /// executor.
57+ ///
58+ /// See also: [`task::block_on`].
59+ ///
60+ /// [`task::block_on`]: fn.block_on.html
61+ ///
62+ /// # Examples
63+ ///
64+ /// Basic usage:
65+ ///
66+ /// ```
67+ /// # fn main() { async_std::task::block_on(async {
68+ /// #
69+ /// use async_std::task;
70+ ///
71+ /// task::blocking(async {
72+ /// println!("long-running task here");
73+ /// }).await;
74+ /// #
75+ /// # }) }
76+ /// ```
5577// Once this function stabilizes we should merge `blocking::spawn` into this so
5678// all code in our crate uses `task::blocking` too.
5779#[ cfg( any( feature = "unstable" , feature = "docs" ) ) ]
You can’t perform that action at this time.
0 commit comments