Skip to content

Commit 525ac9f

Browse files
author
Stjepan Glavina
committed
Comments
1 parent 8cea09d commit 525ac9f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,19 @@ impl Executor {
102102
future: impl Future<Output = T> + Send + 'static,
103103
) -> Task<T> {
104104
let mut active = self.state().active.lock().unwrap();
105+
106+
// Remove the task from the set of active tasks when the future finishes.
105107
let index = active.next_vacant();
106108
let state = self.state().clone();
107109
let future = async move {
108110
let _guard = CallOnDrop(move || drop(state.active.lock().unwrap().remove(index)));
109111
future.await
110112
};
111113

114+
// Create the task and register it in the set of active tasks.
112115
let (runnable, task) = async_task::spawn(future, self.schedule());
113116
active.insert(runnable.waker());
117+
114118
runnable.schedule();
115119
task
116120
}
@@ -304,15 +308,19 @@ impl LocalExecutor {
304308
/// ```
305309
pub fn spawn<T: 'static>(&self, future: impl Future<Output = T> + 'static) -> Task<T> {
306310
let mut active = self.inner().state().active.lock().unwrap();
311+
312+
// Remove the task from the set of active tasks when the future finishes.
307313
let index = active.next_vacant();
308314
let state = self.inner().state().clone();
309315
let future = async move {
310316
let _guard = CallOnDrop(move || drop(state.active.lock().unwrap().remove(index)));
311317
future.await
312318
};
313319

320+
// Create the task and register it in the set of active tasks.
314321
let (runnable, task) = async_task::spawn_local(future, self.schedule());
315322
active.insert(runnable.waker());
323+
316324
runnable.schedule();
317325
task
318326
}

0 commit comments

Comments
 (0)