0

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?

McMurphy
  • 1,235
  • 1
  • 15
  • 39
  • 1
    HTTP responses are just a stream of bytes, there is no guarantee whatsoever on how it's chunked in your reader, it's dependent on how TCP decided to split it into packets. There is nothing reliable about the way TCP might do that. Larger buffers do not affect this issue. Yes of course you have to deal with split objects, you need either some kind of framing mechanism, or just serialize/deserialize a whole array into the response. – Charlieface May 30 '23 at 00:30

1 Answers1

0

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!

McMurphy
  • 1,235
  • 1
  • 15
  • 39