pub fn pair<R: Read + Send + 'static>(
reader: R,
) -> (InterruptReader<R>, Interruptor)Expand description
Returns a pair of an InterruptReader and an Interruptor.
When you call any of the reading methods of InterruptReader, the
current thread will block, being unblocked only if:
- The underlying
Reader has more bytes or returned anError. - The
Interruptor::interruptfunction was called.
In the former case, it works just like a regular read, giving an
std::io::Result, depending on the operation.
If the latter happens, however, an Error of type
ErrorKind::Other with a payload of InterruptReceived,
meaning that reading operations have been interrupted for some
user defined reason.
You can check if an std::io::Error is of this type by
calling the is_interrupt function.
If the channel was interrupted this way, further reads will work just fine, until another interrupt comes through, creating a read/interrupt cycle.
Behind the scenes, this is done through channels and a spawned thread, but no timeout is used, all operations are blocking.