Skip to content

Commit a5d8d15

Browse files
yilinweicramertj
authored andcommitted
Rename poll_one and poll to try_run_one and run_until_stalled
1 parent 6ef448e commit a5d8d15

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

futures-executor/src/local_pool.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl LocalPool {
147147
/// The function will block the calling thread *only* until the future `f`
148148
/// completes; there may still be incomplete tasks in the pool, which will
149149
/// be inert after the call completes, but can continue with further use of
150-
/// one of the pool's run or poll mothods. While the function is running,
150+
/// one of the pool's run or poll methods. While the function is running,
151151
/// however, all tasks in the pool will try to make progress.
152152
pub fn run_until<F: Future>(&mut self, future: F) -> F::Output {
153153
pin_mut!(future);
@@ -183,19 +183,19 @@ impl LocalPool {
183183
/// spawner.spawn_local(empty());
184184
///
185185
/// // Run the two ready tasks and return true for them.
186-
/// pool.poll_one(); // returns true after completing one of the ready futures
187-
/// pool.poll_one(); // returns true after completing the other ready future
186+
/// pool.try_run_one(); // returns true after completing one of the ready futures
187+
/// pool.try_run_one(); // returns true after completing the other ready future
188188
///
189189
/// // the remaining task can not be completed
190-
/// pool.poll_one(); // returns false
190+
/// pool.try_run_one(); // returns false
191191
/// ```
192192
///
193193
/// This function will not block the calling thread and will return the moment
194194
/// that there are no tasks left for which progress can be made or after exactly one
195195
/// task was completed; Remaining incomplete tasks in the pool can continue with
196196
/// further use of one of the pool's run or poll methods.
197197
/// Though only one task will be completed, progress may be made on multiple tasks.
198-
pub fn poll_one(&mut self) -> bool {
198+
pub fn try_run_one(&mut self) -> bool {
199199
poll_executor(|ctx| {
200200
let ret = self.poll_pool_once(ctx);
201201

@@ -225,15 +225,15 @@ impl LocalPool {
225225
///
226226
/// // Runs the two ready task and returns.
227227
/// // The empty task remains in the pool.
228-
/// pool.poll();
228+
/// pool.run_until_stalled();
229229
/// ```
230230
///
231231
/// This function will not block the calling thread and will return the moment
232232
/// that there are no tasks left for which progress can be made;
233233
/// remaining incomplete tasks in the pool can continue with further use of one
234234
/// of the pool's run or poll methods. While the function is running, all tasks
235235
/// in the pool will try to make progress.
236-
pub fn poll(&mut self) {
236+
pub fn run_until_stalled(&mut self) {
237237
poll_executor(|ctx| {
238238
loop {
239239
let result = self.poll_pool_once(ctx);

futures-executor/tests/local_pool.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ fn run_spawn_many() {
111111
}
112112

113113
#[test]
114-
fn poll_one_returns_if_empty() {
114+
fn try_run_one_returns_if_empty() {
115115
let mut pool = LocalPool::new();
116-
assert!(pool.poll_one() == false);
116+
assert!(pool.try_run_one() == false);
117117
}
118118

119119
#[test]
120-
fn poll_one_executes_one_ready() {
120+
fn try_run_one_executes_one_ready() {
121121
const ITER: usize = 200;
122122

123123
let cnt = Rc::new(Cell::new(0));
@@ -139,14 +139,14 @@ fn poll_one_executes_one_ready() {
139139

140140
for i in 0..ITER {
141141
assert_eq!(cnt.get(), i);
142-
assert!(pool.poll_one());
142+
assert!(pool.try_run_one());
143143
assert_eq!(cnt.get(), i + 1);
144144
}
145-
assert!(pool.poll_one() == false);
145+
assert!(pool.try_run_one() == false);
146146
}
147147

148148
#[test]
149-
fn poll_one_returns_on_no_progress() {
149+
fn try_run_one_returns_on_no_progress() {
150150
const ITER: usize = 10;
151151

152152
let cnt = Rc::new(Cell::new(0));
@@ -171,42 +171,42 @@ fn poll_one_returns_on_no_progress() {
171171

172172
for i in 0..ITER - 1 {
173173
assert_eq!(cnt.get(), i);
174-
assert!(!pool.poll_one());
174+
assert!(!pool.try_run_one());
175175
assert_eq!(cnt.get(), i + 1);
176176
let w = waker.take();
177177
assert!(w.is_some());
178178
w.unwrap().wake();
179179
}
180-
assert!(pool.poll_one());
180+
assert!(pool.try_run_one());
181181
assert_eq!(cnt.get(), ITER);
182182
}
183183

184184
#[test]
185-
fn poll_returns_if_empty() {
185+
fn run_until_stalled_returns_if_empty() {
186186
let mut pool = LocalPool::new();
187-
pool.poll();
188-
pool.poll();
187+
pool.run_until_stalled();
188+
pool.run_until_stalled();
189189
}
190190

191191
#[test]
192-
fn poll_returns_multiple_times() {
192+
fn run_until_stalled_returns_multiple_times() {
193193
let mut pool = LocalPool::new();
194194
let mut spawn = pool.spawner();
195195
let cnt = Rc::new(Cell::new(0));
196196

197197
let cnt1 = cnt.clone();
198198
spawn.spawn_local_obj(Box::pin(lazy(move |_|{ cnt1.set(cnt1.get() + 1) })).into()).unwrap();
199-
pool.poll();
199+
pool.run_until_stalled();
200200
assert_eq!(cnt.get(), 1);
201201

202202
let cnt2 = cnt.clone();
203203
spawn.spawn_local_obj(Box::pin(lazy(move |_|{ cnt2.set(cnt2.get() + 1) })).into()).unwrap();
204-
pool.poll();
204+
pool.run_until_stalled();
205205
assert_eq!(cnt.get(), 2);
206206
}
207207

208208
#[test]
209-
fn poll_executes_all_ready() {
209+
fn run_until_stalled_executes_all_ready() {
210210
const ITER: usize = 200;
211211
const PER_ITER: usize = 3;
212212

@@ -229,7 +229,7 @@ fn poll_executes_all_ready() {
229229
spawn.spawn_local_obj(Box::pin(pending()).into()).unwrap();
230230
}
231231
assert_eq!(cnt.get(), i * PER_ITER);
232-
pool.poll();
232+
pool.run_until_stalled();
233233
assert_eq!(cnt.get(), (i + 1) * PER_ITER);
234234
}
235235
}
@@ -250,13 +250,13 @@ fn nesting_run() {
250250

251251
#[test]
252252
#[should_panic]
253-
fn nesting_run_poll() {
253+
fn nesting_run_run_until_stalled() {
254254
let mut pool = LocalPool::new();
255255
let mut spawn = pool.spawner();
256256

257257
spawn.spawn_obj(Box::pin(lazy(|_| {
258258
let mut pool = LocalPool::new();
259-
pool.poll();
259+
pool.run_until_stalled();
260260
})).into()).unwrap();
261261

262262
pool.run();

0 commit comments

Comments
 (0)