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
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);
Cancellable future for futures 0.1
Future for the
Result returned by
An extension trait for
Creates a new