From 525ac9fe7edddcc864ece8118f0728e0c4ece4ea Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Sun, 20 Sep 2020 02:38:56 +0200 Subject: [PATCH] Comments --- src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b3a7ae3..542356d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,6 +102,8 @@ impl Executor { future: impl Future + Send + 'static, ) -> Task { let mut active = self.state().active.lock().unwrap(); + + // Remove the task from the set of active tasks when the future finishes. let index = active.next_vacant(); let state = self.state().clone(); let future = async move { @@ -109,8 +111,10 @@ impl Executor { future.await }; + // Create the task and register it in the set of active tasks. let (runnable, task) = async_task::spawn(future, self.schedule()); active.insert(runnable.waker()); + runnable.schedule(); task } @@ -304,6 +308,8 @@ impl LocalExecutor { /// ``` pub fn spawn(&self, future: impl Future + 'static) -> Task { let mut active = self.inner().state().active.lock().unwrap(); + + // Remove the task from the set of active tasks when the future finishes. let index = active.next_vacant(); let state = self.inner().state().clone(); let future = async move { @@ -311,8 +317,10 @@ impl LocalExecutor { future.await }; + // Create the task and register it in the set of active tasks. let (runnable, task) = async_task::spawn_local(future, self.schedule()); active.insert(runnable.waker()); + runnable.schedule(); task }