AsyncEx
AsyncEx copied to clipboard
AsyncStream helper class
I have recently used the AsyncEx librairies in a personal GitHub project and I identified an helper class which could be added to it.
I have called it AsyncStream as it is the asynchronous version of the System.IO.Stream class.
It can be used to create a custom implementation of the Sytem.IO.Stream class by overriding only asynchronous ReadAsync, WriteAsync and FlushAsync methods.
Would it fit in well with AsyncEx ?
I have just discovered that @StephenCleary has already written such a class that he called AsyncStreamBase inside the ProducerConsumerStream repository.
It is quite the same approach, except that the protected methods have an additional bool sync parameter… I do not see why we should support a sync mode inside an async method !?!
Does someone have an explanation ?
I've not seen that particular class, but being familiar with Stephen's style, I'd surmise that the class exposes both synchronous and asynchronous api. The "bool sync" parameter is used by stephen to allow the public synchronous methods to re-use code that is also used by the public asynchronous methods, when there is no way to avoid having the synchronous method synchronously wait on async code.
Yes, the bool sync technique is described here: https://msdn.microsoft.com/en-us/magazine/mt238404.aspx
Thanks, now I understand the intent of the bool sync pattern.
I have updated the AsyncStream class inside my project accordingly.
I propose to add it as an helper class to the AsyncEx library. Do you agree ?
If yes, are you interested in a PR from me ?