Skip to content

Commit b551985

Browse files
author
Stjepan Glavina
authored
Merge pull request #14 from Keruspe/local
add Executor::is_empty and LocalExecutor::is_empty
2 parents 29ba8a7 + 5a5ecd2 commit b551985

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ impl<'a> Executor<'a> {
214214
future.or(run_forever).await
215215
}
216216

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+
217222
/// Returns a function that schedules a runnable task when it gets woken up.
218223
fn schedule(&self) -> impl Fn(Runnable) + Send + Sync + 'static {
219224
let state = self.state().clone();
@@ -393,6 +398,11 @@ impl<'a> LocalExecutor<'a> {
393398
self.inner().run(future).await
394399
}
395400

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+
396406
/// Returns a function that schedules a runnable task when it gets woken up.
397407
fn schedule(&self) -> impl Fn(Runnable) + Send + Sync + 'static {
398408
let state = self.inner().state().clone();

0 commit comments

Comments
 (0)