Skip to content

Commit 984cd00

Browse files
committed
Propagate panics in tasks
After smol-rs/async-task#37 I meant to add this to the executor. This commit makes it so all panics are surfaced in the tasks that the user calls. Hopefully this improves ergonomics. Signed-off-by: John Nunley <[email protected]>
1 parent 144b057 commit 984cd00

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/lib.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use std::sync::{Arc, Mutex, RwLock, TryLockError};
4343
use std::task::{Poll, Waker};
4444

4545
use async_lock::OnceCell;
46-
use async_task::Runnable;
46+
use async_task::{Builder, Runnable};
4747
use concurrent_queue::ConcurrentQueue;
4848
use futures_lite::{future, prelude::*};
4949
use slab::Slab;
@@ -159,7 +159,11 @@ impl<'a> Executor<'a> {
159159
};
160160

161161
// Create the task and register it in the set of active tasks.
162-
let (runnable, task) = unsafe { async_task::spawn_unchecked(future, self.schedule()) };
162+
let (runnable, task) = unsafe {
163+
Builder::new()
164+
.propagate_panic(true)
165+
.spawn_unchecked(|()| future, self.schedule())
166+
};
163167
active.insert(runnable.waker());
164168

165169
runnable.schedule();
@@ -402,7 +406,11 @@ impl<'a> LocalExecutor<'a> {
402406
};
403407

404408
// Create the task and register it in the set of active tasks.
405-
let (runnable, task) = unsafe { async_task::spawn_unchecked(future, self.schedule()) };
409+
let (runnable, task) = unsafe {
410+
Builder::new()
411+
.propagate_panic(true)
412+
.spawn_unchecked(|()| future, self.schedule())
413+
};
406414
active.insert(runnable.waker());
407415

408416
runnable.schedule();

0 commit comments

Comments
 (0)