smol-rs/async-task

Option to avoid panicking when polling a cancelled task

mystor opened this issue · 3 comments

In panic=abort environments, currently polling a Task which was cancelled due to the Runnable being dropped will cause a panic and abort the entire panicking process.

Poll::Ready(t) => Poll::Ready(t.expect("task has failed")),

It would be nice to have an alternative option for polling cancelled runnables which doesn't panic, either producing a Result or Option to indicate that the task was cancelled, or continuing to produce poll::Pending and cancelling the blocked task silently (e.g. by dropping the waker).

Exposing the Task<T>::poll_task method publicly should be sufficient to allow downstream crates to customize the behavior they want with wrappers, though async_task could also expose a wrapper type itself which delegates the Future::poll implementation directly to poll_task without the unwrap call.

I would accept a PR to add a fallible wrapper.

@taiki-e Would it be possible to cut a new release with this change? Would be slightly preferable to a pinned git revision.

Published in 4.1.0.