#future #cancel #abort #task #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

#1654 in Asynchronous

21 downloads per month

Apache-2.0/MIT

16KB
186 lines

About

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

License

Licensed under either of

at your option.


lib.rs:

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

Example

 use kyansel::cancellable;

 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);
#

Dependencies

~14KB