bc-csharp icon indicating copy to clipboard operation
bc-csharp copied to clipboard

Async methods for Asn1InputStream

Open boomer41 opened this issue 1 year ago • 2 comments

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.

boomer41 avatar Jun 20 '23 07:06 boomer41

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.

harrison314 avatar Jun 23 '23 12:06 harrison314

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).

peterdettman avatar Jun 28 '23 06:06 peterdettman