Expand description
This module contains functions for reading in a background thread.
- The simplest to use is the
reader
function. It accepts anyio::Read
instance that implementsSend
. - The
reader_init
function handles cases where the wrapped reader cannot be sent safely across the thread boundary by providing a closure for initializing the reader in the background thread.
Error handling
io::Error
s occuring during reading in the background are returned by theread
method of the reader in the main thread as expected, but with a delay of at east one call.- Reading errors cause the background reader to stop, except for errors
of kind
io::ErrorKind::Interrupted
. In this case reading continues in background, allowing the user to resume reading after the error occurred. - The
func
closure running in the main thread allows returning errors of any type. If a reading error happens around the same time in the background thread and does not reach the main thread due to the reporting delay, it will be discarded and the error fromfunc
returned instead. - panics in the background reader are correctly forwarded to the main
thread, but are also given lower priority if an error is returned from
func
.
Structs
- The reader in the main thread
Functions
- Sends
reader
to a background thread and provides a reader in the main thread, which obtains data from the background reader. - Like
reader()
, but the wrapped reader is initialized in a closure (init_reader
) in the background thread. This allows using readers that don’t implementSend