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::Interrupted will be received, meaning that reading
operations have been interrupted for some user defined reason.
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.