@@ -18,11 +18,10 @@ use std::task::{Context, Poll, Waker};
1818
1919pub mod batch_semaphore;
2020
21- /// Spawn a new async task that the executor will run to completion.
22- pub fn spawn < T , F > ( fut : F ) -> JoinHandle < T >
21+ fn spawn_inner < F > ( fut : F ) -> JoinHandle < F :: Output >
2322where
24- F : Future < Output = T > + Send + ' static ,
25- T : Send + ' static ,
23+ F : Future + ' static ,
24+ F :: Output : ' static ,
2625{
2726 let stack_size = ExecutionState :: with ( |s| s. config . stack_size ) ;
2827 let inner = Arc :: new ( std:: sync:: Mutex :: new ( JoinHandleInner :: default ( ) ) ) ;
3332 JoinHandle { task_id, inner }
3433}
3534
35+ /// Spawn a new async task that the executor will run to completion.
36+ pub fn spawn < F > ( fut : F ) -> JoinHandle < F :: Output >
37+ where
38+ F : Future + Send + ' static ,
39+ F :: Output : Send + ' static ,
40+ {
41+ spawn_inner ( fut)
42+ }
43+
44+ /// Spawn a new async task that the executor will run to completion.
45+ /// This is just `spawn` without the `Send` bound, and it mirrors `spawn_local` from Tokio.
46+ pub fn spawn_local < F > ( fut : F ) -> JoinHandle < F :: Output >
47+ where
48+ F : Future + ' static ,
49+ F :: Output : ' static ,
50+ {
51+ spawn_inner ( fut)
52+ }
53+
3654/// An owned permission to join on an async task (await its termination).
3755#[ derive( Debug ) ]
3856pub struct JoinHandle < T > {
@@ -120,27 +138,28 @@ impl<T> Future for JoinHandle<T> {
120138// contains a mutex-wrapped field that stores the value and the waker for the task
121139// waiting on the join handle. When `poll` returns `Poll::Ready`, the `Wrapper` stores
122140// the result in the `result` field and wakes the `waker`.
123- struct Wrapper < T , F > {
141+ struct Wrapper < F : Future > {
124142 future : Pin < Box < F > > ,
125- inner : std:: sync:: Arc < std:: sync:: Mutex < JoinHandleInner < T > > > ,
143+ inner : std:: sync:: Arc < std:: sync:: Mutex < JoinHandleInner < F :: Output > > > ,
126144}
127145
128- impl < T , F > Wrapper < T , F >
146+ impl < F > Wrapper < F >
129147where
130- F : Future < Output = T > + Send + ' static ,
148+ F : Future + ' static ,
149+ F :: Output : ' static ,
131150{
132- fn new ( future : F , inner : std:: sync:: Arc < std:: sync:: Mutex < JoinHandleInner < T > > > ) -> Self {
151+ fn new ( future : F , inner : std:: sync:: Arc < std:: sync:: Mutex < JoinHandleInner < F :: Output > > > ) -> Self {
133152 Self {
134153 future : Box :: pin ( future) ,
135154 inner,
136155 }
137156 }
138157}
139158
140- impl < T , F > Future for Wrapper < T , F >
159+ impl < F > Future for Wrapper < F >
141160where
142- F : Future < Output = T > + Send + ' static ,
143- T : Send + ' static ,
161+ F : Future + ' static ,
162+ F :: Output : ' static ,
144163{
145164 type Output = ( ) ;
146165
0 commit comments