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 |
#2007 in Asynchronous
40 downloads per month
16KB
186 lines
About
Simple crate that provides a combinator future that will cancel when the passed future completes
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
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