Search code examples
c#jsonhttprequeststreamingiasyncenumerable

IAsyncEnumerable chunk-size throttle(s) and format conventions for HttpResponse JSON


I have observed that if I increase the interval between my .NET C# Controller method Yields like: -

   await Task.Delay(100);  // Slow down the Demo

That each server yield corresponds 1:1 to a Javascript: -

response.body.getReader()  read()

But at full-speed the results are buffered to "N" byte chunks of JSON.

EDIT 2

My question is:

Can someone please provide an example or a link to the appropriate documentation of the correct way for Javascript to process a FETCH response from a C# .NET IASyncEnumerable controller method? Thank you for reading.

Final EDIT Please re-open for others

My question is, how can I replicate the C# functionality afforded by: -

JsonSerializer.DeserializeAsyncEnumerable

an example of which can be found here, in Javascript?


Solution

  • A SSCCE of the correct Javascript answer can be found in this Visual Studio Solution: ChunkIt

    If you look at the pipeFactory you see that, unfortunately, Javascript programmers have to write our own iterator to handle tears in the JSON but the end result is more than worth it!