add Executor::is_empty and LocalExecutor::is_empty

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
This commit is contained in:
Marc-Antoine Perennou 2020-11-06 18:29:30 +01:00
parent 29ba8a72ad
commit 5a5ecd2763
1 changed files with 10 additions and 0 deletions

View File

@ -214,6 +214,11 @@ impl<'a> Executor<'a> {
future.or(run_forever).await
}
/// Checks if the executor is empty and has no pending tasks to run.
pub fn is_empty(&self) -> bool {
self.state().active.lock().unwrap().is_empty()
}
/// Returns a function that schedules a runnable task when it gets woken up.
fn schedule(&self) -> impl Fn(Runnable) + Send + Sync + 'static {
let state = self.state().clone();
@ -393,6 +398,11 @@ impl<'a> LocalExecutor<'a> {
self.inner().run(future).await
}
/// Checks if the executor is empty and has no pending tasks to run.
pub fn is_empty(&self) -> bool {
self.inner().is_empty()
}
/// Returns a function that schedules a runnable task when it gets woken up.
fn schedule(&self) -> impl Fn(Runnable) + Send + Sync + 'static {
let state = self.inner().state().clone();