File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -96,12 +96,13 @@ fn schedule(t: async_task::Task<Tag>) {
96
96
/// Spawns a blocking task.
97
97
///
98
98
/// 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 >
100
100
where
101
- F : Future < Output = R > + Send + ' static ,
101
+ F : FnOnce ( ) -> R + Send + ' static ,
102
102
R : Send + ' static ,
103
103
{
104
104
let tag = Tag :: new ( None ) ;
105
+ let future = async move { f ( ) } ;
105
106
let ( task, handle) = async_task:: spawn ( future, schedule, tag) ;
106
107
task. schedule ( ) ;
107
108
JoinHandle :: new ( handle)
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ cfg_if::cfg_if! {
73
73
/// #
74
74
/// use async_std::task;
75
75
///
76
- /// task::blocking(async {
76
+ /// task::blocking(|| {
77
77
/// println!("long-running task here");
78
78
/// }).await;
79
79
/// #
@@ -84,10 +84,10 @@ cfg_if::cfg_if! {
84
84
#[ cfg( any( feature = "unstable" , feature = "docs" ) ) ]
85
85
#[ cfg_attr( feature = "docs" , doc( cfg( unstable) ) ) ]
86
86
#[ inline]
87
- pub fn blocking < F , R > ( future : F ) -> task:: JoinHandle < R >
87
+ pub fn blocking < F , R > ( f : F ) -> task:: JoinHandle < R >
88
88
where
89
- F : crate :: future :: Future < Output = R > + Send + ' static ,
89
+ F : FnOnce ( ) -> R + Send + ' static ,
90
90
R : Send + ' static ,
91
91
{
92
- blocking:: spawn ( future)
92
+ blocking:: spawn_blocking ( future)
93
93
}
You can’t perform that action at this time.
0 commit comments