futures-rs
futures-rs copied to clipboard
Change the output of `RemoteHandle<T>` to `Option<T>` for checking `Remote` cancellation reliably
Currently, std::panic::resume_unwind is called if I await a RemoteHandle with a canceled Remote future:
https://github.com/rust-lang/futures-rs/blob/96c2fc4668f8bfb428352e8a1558972961bd31a1/futures-util/src/future/future/remote_handle.rs#L65-L66
But https://doc.rust-lang.org/std/panic/fn.resume_unwind.html#notes says that
panics in Rust are not always implemented via unwinding, but they may be implemented by aborting the process
which means cancelling a Remote future might terminate the process immediately and there is no way to avoid it. This might be a little dangerous. Here are my suggestions:
- Warn user that
awaiting aRemoteHandlewhoseRemotefuture is canceled before ready will panic theawaiting thread, maybe also suggest user to useOneShotchannel manually for reliable cancellation checking. - Change the output type of
RemoteHandle<T>toOption<T>orResult<T, Canceled>. This will break many existing programs due to API change, but maybe change it on the next major version?