do
{
bufferState = await ReadFromStreamAsync(utf8Json, bufferState, cancellationToken).ConfigureAwait(false);
- Queue<TValue>? queue = ContinueDeserialize<Queue<TValue>>(ref bufferState, ref jsonReaderState, ref readStack, converter, options);
- if (queue is not null)
+ ContinueDeserialize<Queue<TValue>>(ref bufferState, ref jsonReaderState, ref readStack, converter, options);
+ if (readStack.Current.ReturnValue is Queue<TValue> queue)
{
while (queue.Count > 0)
{
}
[Fact]
+ public static async Task DeserializeAsyncEnumerable_ShouldStreamPartialData()
+ {
+ string json = JsonSerializer.Serialize(Enumerable.Range(0, 100));
+
+ using var stream = new Utf8MemoryStream(json);
+ IAsyncEnumerable<int> asyncEnumerable = JsonSerializer.DeserializeAsyncEnumerable<int>(stream, new JsonSerializerOptions { DefaultBufferSize = 1 });
+ await using IAsyncEnumerator<int> asyncEnumerator = asyncEnumerable.GetAsyncEnumerator();
+
+ for (int i = 0; i < 20; i++)
+ {
+ bool success = await asyncEnumerator.MoveNextAsync();
+ Assert.True(success, "AsyncEnumerator.MoveNextAsync() should return true.");
+ Assert.True(stream.Position < stream.Capacity / 2, "should have consumed less than half of the stream contents.");
+ }
+ }
+
+ [Fact]
public static async Task DeserializeAsyncEnumerable_ShouldTolerateCustomQueueConverters()
{
const int expectedCount = 20;