bc-csharp
bc-csharp copied to clipboard
Async methods for Asn1InputStream
It would be very handy to have a ReadObjectAsync() method in Asn1InputStream with CancellationToken support. This way when trying to read ASN.1 objects from a FileStream or a HTTP Stream, calls would not block the whole worker thread when programming in an fully asynchronous service.
I solved this problem by reading the ASN1 object into the MemoryStream (or RecyclableMemoryStream) asynchronously and then using ReadObject synchronously on the MemoryStream.
It's a workaround, but it minimizes fiber blocking.
I think separating the async IO from the parsing as @harrison314 gives an example approach for, is the best we can do for the moment. Perhaps it would be useful to add helpers for async reading from a File or Stream (with size limit guard), where the whole contents would be expected (required) to be either a single ASN.1 object or a series of them (separate methods).