File tree 2 files changed +27
-1
lines changed
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;
19
19
/// Calling this function is similar to [spawning] a thread and immediately [joining] it, except an
20
20
/// asynchronous task will be spawned.
21
21
///
22
+ /// See also: [`task::blocking`].
23
+ ///
24
+ /// [`task::blocking`]: fn.blocking.html
25
+ ///
22
26
/// [spawning]: https://doc.rust-lang.org/std/thread/fn.spawn.html
23
27
/// [joining]: https://doc.rust-lang.org/std/thread/struct.JoinHandle.html#method.join
24
28
///
Original file line number Diff line number Diff line change @@ -51,7 +51,29 @@ pub(crate) mod blocking;
51
51
52
52
/// Spawns a blocking task.
53
53
///
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
+ /// ```
55
77
// Once this function stabilizes we should merge `blocking::spawn` into this so
56
78
// all code in our crate uses `task::blocking` too.
57
79
#[ cfg( any( feature = "unstable" , feature = "docs" ) ) ]
You can’t perform that action at this time.
0 commit comments