#futures #task #cancel #abort #no-std

no-std kyansel

Cancellable future. Provide a future as argument and the current future will cancel if the provided future resolves first

5 unstable releases

0.3.1 Nov 22, 2019
0.3.0 Nov 22, 2019
0.2.1 Nov 19, 2019
0.2.0 Nov 19, 2019
0.1.0 Nov 18, 2019

#379 in Asynchronous

25 downloads per month


186 lines


Simple crate that provides a combinator future that will cancel when the passed future completes


Licensed under either of

at your option.


This library adds a combinator for futures, enabling a future to be cancelled when another one has completed succesfully.

Support for futures 0.1 can be enabled with the futures_01 feature


# #[tokio::main]
# async fn main() -> Result<(), Box<dyn std::error::Error>> {
#    use futures::future::{join, ready};
 use kyansel::cancellable;
#    use tokio::{sync::oneshot, timer::delay};

 let (tx, rx) = oneshot::channel::<()>();
 //simulate a long future
 let future =
     delay(tokio::clock::now() + std::time::Duration::from_secs(1));

 //make it cancellable
 let cancellable = cancellable(future, rx);

 //create the future that will trigger the cancellation
 let canceller = ready(tx.send(()));

 //run them at the same time (example)
 let pair = join(cancellable, canceller);

 //we `.await` the join, dropping the result of the canceller since we don't care
 let (cancellable_result, _) = pair.await;

 //the return is of type CancelledResult<(), Result<(), RecvError>>
 let cancellable_result = cancellable_result.cancelled().unwrap().unwrap();

 assert_eq!((), cancellable_result);
# Ok(())
# }