Function ctx::with_cancel
[−]
[src]
pub fn with_cancel(parent: Context) -> (Context, Box<Fn() + Send>)
Returns a copy of parent as a new future, which is closed when the returned cancel function is called or when the parent context's future is resolved – whichever happens first.
Example
extern crate ctx; extern crate futures; use ctx::{Context, ContextError, with_cancel, background}; use futures::future::Future; fn main() { let (ctx, cancel) = with_cancel(background()); cancel(); assert_eq!(ctx.wait().unwrap_err(), ContextError::Canceled); }