@@ -92,6 +92,28 @@ impl<'a> Executor<'a> {
92
92
}
93
93
}
94
94
95
+ /// Returns `true` if there are no unfinished tasks.
96
+ ///
97
+ /// # Examples
98
+ ///
99
+ /// ```
100
+ /// use async_executor::Executor;
101
+ ///
102
+ /// let ex = Executor::new();
103
+ /// assert!(ex.is_empty());
104
+ ///
105
+ /// let task = ex.spawn(async {
106
+ /// println!("Hello world");
107
+ /// });
108
+ /// assert!(!ex.is_empty());
109
+ ///
110
+ /// assert!(ex.try_tick());
111
+ /// assert!(ex.is_empty());
112
+ /// ```
113
+ pub fn is_empty ( & self ) -> bool {
114
+ self . state ( ) . active . lock ( ) . unwrap ( ) . is_empty ( )
115
+ }
116
+
95
117
/// Spawns a task onto the executor.
96
118
///
97
119
/// # Examples
@@ -156,7 +178,7 @@ impl<'a> Executor<'a> {
156
178
}
157
179
}
158
180
159
- /// Run a single task.
181
+ /// Runs a single task.
160
182
///
161
183
/// Running a task means simply polling its future once.
162
184
///
@@ -214,11 +236,6 @@ impl<'a> Executor<'a> {
214
236
future. or ( run_forever) . await
215
237
}
216
238
217
- /// Checks if the executor is empty and has no pending tasks to run.
218
- pub fn is_empty ( & self ) -> bool {
219
- self . state ( ) . active . lock ( ) . unwrap ( ) . is_empty ( )
220
- }
221
-
222
239
/// Returns a function that schedules a runnable task when it gets woken up.
223
240
fn schedule ( & self ) -> impl Fn ( Runnable ) + Send + Sync + ' static {
224
241
let state = self . state ( ) . clone ( ) ;
@@ -303,6 +320,28 @@ impl<'a> LocalExecutor<'a> {
303
320
}
304
321
}
305
322
323
+ /// Returns `true` if there are no unfinished tasks.
324
+ ///
325
+ /// # Examples
326
+ ///
327
+ /// ```
328
+ /// use async_executor::LocalExecutor;
329
+ ///
330
+ /// let local_ex = LocalExecutor::new();
331
+ /// assert!(local_ex.is_empty());
332
+ ///
333
+ /// let task = local_ex.spawn(async {
334
+ /// println!("Hello world");
335
+ /// });
336
+ /// assert!(!local_ex.is_empty());
337
+ ///
338
+ /// assert!(local_ex.try_tick());
339
+ /// assert!(local_ex.is_empty());
340
+ /// ```
341
+ pub fn is_empty ( & self ) -> bool {
342
+ self . inner ( ) . is_empty ( )
343
+ }
344
+
306
345
/// Spawns a task onto the executor.
307
346
///
308
347
/// # Examples
@@ -356,7 +395,7 @@ impl<'a> LocalExecutor<'a> {
356
395
self . inner ( ) . try_tick ( )
357
396
}
358
397
359
- /// Run a single task.
398
+ /// Runs a single task.
360
399
///
361
400
/// Running a task means simply polling its future once.
362
401
///
@@ -398,11 +437,6 @@ impl<'a> LocalExecutor<'a> {
398
437
self . inner ( ) . run ( future) . await
399
438
}
400
439
401
- /// Checks if the executor is empty and has no pending tasks to run.
402
- pub fn is_empty ( & self ) -> bool {
403
- self . inner ( ) . is_empty ( )
404
- }
405
-
406
440
/// Returns a function that schedules a runnable task when it gets woken up.
407
441
fn schedule ( & self ) -> impl Fn ( Runnable ) + Send + Sync + ' static {
408
442
let state = self . inner ( ) . state ( ) . clone ( ) ;
0 commit comments