[][src]Module thread_io::read

This module contains functions for reading in a background thread.

  • The simplest to use is the reader function. It accepts any io::Read instance that implements Send.
  • 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::Errors occuring during reading in the background are returned by the read 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 from func 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

Reader

The reader in the main thread

Functions

reader

Sends reader to a background thread and provides a reader in the main thread, which obtains data from the background reader.

reader_init

Like reader(), but the wrapped reader is initialized in a closure (init_reader) in the background thread. This allows using readers that don't implement Send