-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Description
I'm downloading a stream from a WebAPI and I'm trying to run code while the stream is being read.
The code below works fine on Blazor server-side or an console app. But on blazor-client side the stream will first download fully before executing any code.... even just a Console.WriteLine() will just start writing to Console after the stream is done. I'm using the latest .Net Core 3.0 Preview 8...
public async IAsyncEnumerable<SomeClass> GetDataAsync()
{
var serializer = new JsonSerializer();
using (var stream = await Http.GetStreamAsync("https://localhost:44334/api/values/i"))
{
using (var sr = new StreamReader(stream))
using (var jr = new JsonTextReader(sr))
{
while (await jr.ReadAsync()) //<-- Stream is fully download to browser before taking any actions.
{
if (jr.TokenType != JsonToken.StartArray && jr.TokenType != JsonToken.EndArray)
{
Console.WriteLine(jsonReader.LinePosition);
yield return serializer.Deserialize<SomeClass>(jr);
}
};
}
}
}
I tested this with WireShark to confirm that this is happening.
Is this by design?
Metadata
Metadata
Assignees
Labels
No labels