Read bytes from an InputSource into a char buffer
.
The reading is done asynchronously, that is, in another thread. This is usually faster than synchronous reading (see SynchronousReader), particularly for large data blocks, because we can avoid blocking any computational threads for I/O wait times. It is thus the preferred reader, if available.
In detail, if we have a trival input source, such as just reading data from a file, it get its own thread pool with one thread, which boils down to just a thread and condition variable for notifying the thread, and hence is a realative lightweight way of not blocking any computational threads with I/O wait times. For more complex inputs, such as gzip that needs decompression, and hence is not a trivial I/O wait, we instead use a given or the global thread pool, to avoid oversubscribing our desired thread count, and spamming too many async reader threads when multiple files need to be processed at the same time.
The caller is responsible for keeping the data buffer alive while the reading is happening. That is, calling start_reading() without then also calling finish_reading() and having the buffer go out of scope could lead to a segfault. Don't do that. Also, each call to start_reading() needs to be matched by a call to finish_reading() before calling start_reading() again, as otherwise, the input data will get scrambled.
Implementation details inspired by fast-cpp-csv-parser by Ben Strasser, see also Acknowledgements.
Definition at line 93 of file input_reader.hpp.