Easy ctrl+c handling with failure and futures.
In many cases, a ctrl+c event from the user is hardly different from
a fatal application error. This crate, inspired by Python's InterruptedException
makes it easy to treat ctrl+c in precisely such a way.
Examples
use *;
use AsyncCtrlc;
let task = lengthy_task.ctrlc_as_error;
let mut rt = new.unwrap;
let res = rt.block_on;
println!;
Usage notes
ctrlc_as_error has the same semantics as select and will return either
the result of the future or an KeyboardInterrupt error, whichever occurs
first. In particular, the interrupt is intercepted only for those futures
in the chain that precede the call. For example:
use Duration;
use *;
use AsyncCtrlc;
let task = sleep
.ctrlc_as_error
.and_then;
let mut rt = new.unwrap;
let res = rt.block_on;
Here, the interrupt will be handled only during the first sleep. During the second sleep, the default handling of the signal will take place.