Open daniel-j-h opened 7 years ago
Here's an idea: we could abstract asynchronous I/O behind the current abstractions. In the design proposal you would have e.g. a AsyncOutStream
. At the moment with our FileReader
and FileWriter
we could add member functions for now.
The FileWriter
could store a vector of std::future<void>
IO actions (make them strictly typed IOActions
), to which you could add your async operation by means of calling a member function.
The FileWriter
's destructor could then block until all IO actions are done. In addition the FileWriter
could allow you to transfer the ownership of the IO action out of the FileWriter
where the user could explicitly block when needed.
The same works for the FileReader
where IO actions could fill elements or return by-value futures (move semantics should make this possible). I see the main benefit primarily in the FileWriter
for now, though.
Currently looking over the extractor and seeing serial I/O there. There is often no need for us waiting for I/O to happen.
For the compressed node based graph dumping I'm doing the following
with the void specialization for future acting as a synchronization point on which we can block when we need to. I think we could do the same in various places there, carefully transferring the future's ownership and only blocking at the end or where it matters.