[][src]Module kyansel::futures_01

Cancellable future for futures 0.1

Example

 use kyansel::futures_01::{CancellableError, FutureCancellable};

 let (tx, rx) = oneshot::channel::<()>();

 let deadline = tokio::clock::now() + std::time::Duration::from_secs(1).into();

 //simulate a long-running future
 let cancellable = Delay::new(deadline)
     .map_err(|_| ())
     .and_then(|_| Ok(()))
     //add a way to cancel it
     .cancel_with(rx)
     .map_err(|e| {
        assert_eq!(e, CancellableError::Cancelled(()));
      })
     .map_err(|_| ());

 let canceller = tx.send(()).into_future();

 run(
   //join it with the canceller
   cancellable.join(canceller)
   //it will cancel immediately returning err
   .and_then(|(_ok, _tx_send)| Ok(println!("unreachable"))),
 );

Structs

Cancellable

Future for the cancel_with combinator, allowing a computation to be cancelled if a second computation completes succesfully.

Enums

CancellableError

Error returned by Cancellable

Traits

FutureCancellable

An extension trait for Future that provides the Cancellable combinator.

Functions

cancellable

Creates a new Cancellable