Struct pawawwewism::reader::Reader
source · pub struct Reader<R: Shutdown, O> { /* private fields */ }
Expand description
An owned thread that reads from a stream.
This type works with streams that can be shut down from another thread (via the Shutdown
trait). That way, the worker thread can perform a blocking read on the stream, while the owning
thread can still make the worker thread exit by shutting down the stream.
When a Reader
is dropped, or Reader::stop
is called, the stream will be shut down and
the thread will be joined. If the thread has panicked, the panic will be propagated to the
owner.
Implementations§
source§impl<R: Shutdown, O> Reader<R, O>
impl<R: Shutdown, O> Reader<R, O>
sourcepub fn spawn<F>(read: R, handler: F) -> Result<Reader<R, O>>where
F: FnOnce(ReadWrapper<&R>) -> Result<O> + Send + 'static,
R: Shutdown + Send + Sync + 'static,
O: Send + 'static,
pub fn spawn<F>(read: R, handler: F) -> Result<Reader<R, O>>where F: FnOnce(ReadWrapper<&R>) -> Result<O> + Send + 'static, R: Shutdown + Send + Sync + 'static, O: Send + 'static,
Spawns a Reader
that will run handler
in a separate thread.
The contract handler
has to uphold is as follows: no blocking I/O must be performed,
except for reading from the ReadWrapper
passed to it.
Also see ReaderBuilder
.
sourcepub fn stop(self) -> Result<O>
pub fn stop(self) -> Result<O>
Stops the Reader
by shutting down the stream it is reading from.
After shutting down the stream, the thread will be joined and its return value will be returned.
If the thread has panicked, the panic will be propagated to the caller.
sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Checks whether the Reader
thread has finished execution.
Reader
s are allowed to return a value from their main function if they choose to exit.
To access that value, call Reader::stop
. They can also “finish” by panicking. Panics are
propagated to the owner.