@@ -92,6 +92,28 @@ impl<'a> Executor<'a> {
9292 }
9393 }
9494
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+
95117 /// Spawns a task onto the executor.
96118 ///
97119 /// # Examples
@@ -156,7 +178,7 @@ impl<'a> Executor<'a> {
156178 }
157179 }
158180
159- /// Run a single task.
181+ /// Runs a single task.
160182 ///
161183 /// Running a task means simply polling its future once.
162184 ///
@@ -214,11 +236,6 @@ impl<'a> Executor<'a> {
214236 future. or ( run_forever) . await
215237 }
216238
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-
222239 /// Returns a function that schedules a runnable task when it gets woken up.
223240 fn schedule ( & self ) -> impl Fn ( Runnable ) + Send + Sync + ' static {
224241 let state = self . state ( ) . clone ( ) ;
@@ -303,6 +320,28 @@ impl<'a> LocalExecutor<'a> {
303320 }
304321 }
305322
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+
306345 /// Spawns a task onto the executor.
307346 ///
308347 /// # Examples
@@ -356,7 +395,7 @@ impl<'a> LocalExecutor<'a> {
356395 self . inner ( ) . try_tick ( )
357396 }
358397
359- /// Run a single task.
398+ /// Runs a single task.
360399 ///
361400 /// Running a task means simply polling its future once.
362401 ///
@@ -398,11 +437,6 @@ impl<'a> LocalExecutor<'a> {
398437 self . inner ( ) . run ( future) . await
399438 }
400439
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-
406440 /// Returns a function that schedules a runnable task when it gets woken up.
407441 fn schedule ( & self ) -> impl Fn ( Runnable ) + Send + Sync + ' static {
408442 let state = self . inner ( ) . state ( ) . clone ( ) ;
0 commit comments