@@ -3,7 +3,7 @@ use futures_core::future::{Future, FutureObj, LocalFutureObj};
3
3
use futures_core:: stream:: { Stream } ;
4
4
use futures_core:: task:: {
5
5
self , Context , Poll , LocalWaker , Wake ,
6
- Executor , SpawnObjError , SpawnLocalObjError , SpawnErrorKind
6
+ Spawn , SpawnObjError , SpawnLocalObjError , SpawnErrorKind
7
7
} ;
8
8
use futures_util:: stream:: FuturesUnordered ;
9
9
use futures_util:: stream:: StreamExt ;
@@ -24,20 +24,20 @@ use std::thread::{self, Thread};
24
24
/// little work in between I/O actions.
25
25
///
26
26
/// To get a handle to the pool that implements
27
- /// [`Executor `](futures_core::task::Executor ), use the
28
- /// [`executor ()`](LocalPool::executor ) method. Because the executor is
27
+ /// [`Spawn `](futures_core::task::Spawn ), use the
28
+ /// [`spawner ()`](LocalPool::spawner ) method. Because the executor is
29
29
/// single-threaded, it supports a special form of task spawning for non-`Send`
30
- /// futures, via [`spawn_local_obj`](LocalExecutor ::spawn_local_obj).
30
+ /// futures, via [`spawn_local_obj`](LocalSpawn ::spawn_local_obj).
31
31
#[ derive( Debug ) ]
32
32
pub struct LocalPool {
33
33
pool : FuturesUnordered < LocalFutureObj < ' static , ( ) > > ,
34
34
incoming : Rc < Incoming > ,
35
35
}
36
36
37
37
/// A handle to a [`LocalPool`](LocalPool) that implements
38
- /// [`Executor `](futures_core::task::Executor ).
38
+ /// [`Spawn `](futures_core::task::Spawn ).
39
39
#[ derive( Clone , Debug ) ]
40
- pub struct LocalExecutor {
40
+ pub struct LocalSpawn {
41
41
incoming : Weak < Incoming > ,
42
42
}
43
43
@@ -59,7 +59,7 @@ impl Wake for ThreadNotify {
59
59
}
60
60
}
61
61
62
- // Set up and run a basic single-threaded executor loop, invocing `f` on each
62
+ // Set up and run a basic single-threaded spawner loop, invoking `f` on each
63
63
// turn.
64
64
fn run_executor < T , F : FnMut ( & LocalWaker ) -> Poll < T > > ( mut f : F ) -> T {
65
65
let _enter = enter ( )
@@ -87,71 +87,71 @@ impl LocalPool {
87
87
}
88
88
}
89
89
90
- /// Get a clonable handle to the pool as an executor .
91
- pub fn executor ( & self ) -> LocalExecutor {
92
- LocalExecutor {
90
+ /// Get a clonable handle to the pool as a [`Spawn`] .
91
+ pub fn spawner ( & self ) -> LocalSpawn {
92
+ LocalSpawn {
93
93
incoming : Rc :: downgrade ( & self . incoming )
94
94
}
95
95
}
96
96
97
97
/// Run all tasks in the pool to completion.
98
98
///
99
- /// The given executor , `exec `, is used as the default executor for any
99
+ /// The given spawner , `spawn `, is used as the default spawner for any
100
100
/// *newly*-spawned tasks. You can route these additional tasks back into
101
- /// the `LocalPool` by using its executor handle:
101
+ /// the `LocalPool` by using its spawner handle:
102
102
///
103
103
/// ```
104
104
/// use futures::executor::LocalPool;
105
105
///
106
106
/// let mut pool = LocalPool::new();
107
- /// let mut exec = pool.executor ();
107
+ /// let mut spawn = pool.spawner ();
108
108
///
109
- /// // ... spawn some initial tasks using `exec .spawn()` or `exec .spawn_local()`
109
+ /// // ... spawn some initial tasks using `spawn .spawn()` or `spawn .spawn_local()`
110
110
///
111
111
/// // run *all* tasks in the pool to completion, including any newly-spawned ones.
112
- /// pool.run(&mut exec );
112
+ /// pool.run(&mut spawn );
113
113
/// ```
114
114
///
115
115
/// The function will block the calling thread until *all* tasks in the pool
116
116
/// are complete, including any spawned while running existing tasks.
117
- pub fn run < Exec > ( & mut self , exec : & mut Exec ) where Exec : Executor + Sized {
118
- run_executor ( |local_waker| self . poll_pool ( local_waker, exec ) )
117
+ pub fn run < Sp > ( & mut self , spawn : & mut Sp ) where Sp : Spawn + Sized {
118
+ run_executor ( |local_waker| self . poll_pool ( local_waker, spawn ) )
119
119
}
120
120
121
121
/// Runs all the tasks in the pool until the given future completes.
122
122
///
123
- /// The given executor , `exec `, is used as the default executor for any
123
+ /// The given spawner , `spawn `, is used as the default spawner for any
124
124
/// *newly*-spawned tasks. You can route these additional tasks back into
125
- /// the `LocalPool` by using its executor handle:
125
+ /// the `LocalPool` by using its spawner handle:
126
126
///
127
127
/// ```
128
128
/// #![feature(pin, arbitrary_self_types, futures_api)]
129
129
/// use futures::executor::LocalPool;
130
130
/// use futures::future::ready;
131
131
///
132
132
/// let mut pool = LocalPool::new();
133
- /// let mut exec = pool.executor ();
133
+ /// let mut spawn = pool.spawner ();
134
134
/// # let my_app = ready(());
135
135
///
136
136
/// // run tasks in the pool until `my_app` completes, by default spawning
137
137
/// // further tasks back onto the pool
138
- /// pool.run_until(my_app, &mut exec );
138
+ /// pool.run_until(my_app, &mut spawn );
139
139
/// ```
140
140
///
141
141
/// The function will block the calling thread *only* until the future `f`
142
142
/// completes; there may still be incomplete tasks in the pool, which will
143
143
/// be inert after the call completes, but can continue with further use of
144
144
/// `run` or `run_until`. While the function is running, however, all tasks
145
145
/// in the pool will try to make progress.
146
- pub fn run_until < F , Exec > ( & mut self , future : F , exec : & mut Exec )
146
+ pub fn run_until < F , Sp > ( & mut self , future : F , spawn : & mut Sp )
147
147
-> F :: Output
148
- where F : Future , Exec : Executor + Sized
148
+ where F : Future , Sp : Spawn + Sized
149
149
{
150
150
pin_mut ! ( future) ;
151
151
152
152
run_executor ( |local_waker| {
153
153
{
154
- let mut main_cx = Context :: new ( local_waker, exec ) ;
154
+ let mut main_cx = Context :: new ( local_waker, spawn ) ;
155
155
156
156
// if our main task is done, so are we
157
157
let result = future. reborrow ( ) . poll ( & mut main_cx) ;
@@ -160,19 +160,19 @@ impl LocalPool {
160
160
}
161
161
}
162
162
163
- self . poll_pool ( local_waker, exec ) ;
163
+ self . poll_pool ( local_waker, spawn ) ;
164
164
Poll :: Pending
165
165
} )
166
166
}
167
167
168
168
// Make maximal progress on the entire pool of spawned task, returning `Ready`
169
169
// if the pool is empty and `Pending` if no further progress can be made.
170
- fn poll_pool < Exec > ( & mut self , local_waker : & LocalWaker , exec : & mut Exec )
170
+ fn poll_pool < Sp > ( & mut self , local_waker : & LocalWaker , spawn : & mut Sp )
171
171
-> Poll < ( ) >
172
- where Exec : Executor + Sized
172
+ where Sp : Spawn + Sized
173
173
{
174
174
// state for the FuturesUnordered, which will never be used
175
- let mut pool_cx = Context :: new ( local_waker, exec ) ;
175
+ let mut pool_cx = Context :: new ( local_waker, spawn ) ;
176
176
177
177
loop {
178
178
// empty the incoming queue of newly-spawned tasks
@@ -215,7 +215,7 @@ lazy_static! {
215
215
/// Run a future to completion on the current thread.
216
216
///
217
217
/// This function will block the caller until the given future has completed.
218
- /// The default executor for the future is a global `ThreadPool`.
218
+ /// The default spawner for the future is a global `ThreadPool`.
219
219
///
220
220
/// Use a [`LocalPool`](LocalPool) if you need finer-grained control over
221
221
/// spawned tasks.
@@ -228,7 +228,7 @@ pub fn block_on<F: Future>(f: F) -> F::Output {
228
228
///
229
229
/// When `next` is called on the resulting `BlockingStream`, the caller
230
230
/// will be blocked until the next element of the `Stream` becomes available.
231
- /// The default executor for the future is a global `ThreadPool`.
231
+ /// The default spawner for the future is a global `ThreadPool`.
232
232
pub fn block_on_stream < S : Stream + Unpin > ( stream : S ) -> BlockingStream < S > {
233
233
BlockingStream { stream }
234
234
}
@@ -264,7 +264,7 @@ impl<S: Stream + Unpin> Iterator for BlockingStream<S> {
264
264
}
265
265
}
266
266
267
- impl Executor for LocalExecutor {
267
+ impl Spawn for LocalSpawn {
268
268
fn spawn_obj (
269
269
& mut self ,
270
270
future : FutureObj < ' static , ( ) > ,
@@ -286,7 +286,7 @@ impl Executor for LocalExecutor {
286
286
}
287
287
}
288
288
289
- impl LocalExecutor {
289
+ impl LocalSpawn {
290
290
/// Spawn a non-`Send` future onto the associated [`LocalPool`](LocalPool).
291
291
pub fn spawn_local_obj (
292
292
& mut self ,
0 commit comments