1 | use super::assert_future; |
2 | use crate::future::{AbortHandle, Abortable, Aborted}; |
3 | use futures_core::future::Future; |
4 | |
5 | /// Creates a new `Abortable` future and an `AbortHandle` which can be used to stop it. |
6 | /// |
7 | /// This function is a convenient (but less flexible) alternative to calling |
8 | /// `AbortHandle::new` and `Abortable::new` manually. |
9 | /// |
10 | /// This function is only available when the `std` or `alloc` feature of this |
11 | /// library is activated, and it is activated by default. |
12 | pub fn abortable<Fut>(future: Fut) -> (Abortable<Fut>, AbortHandle) |
13 | where |
14 | Fut: Future, |
15 | { |
16 | let (handle, reg) = AbortHandle::new_pair(); |
17 | let abortable = assert_future::<Result<Fut::Output, Aborted>, _>(Abortable::new(future, reg)); |
18 | (abortable, handle) |
19 | } |
20 | |