iasyncenumerable

Clarification on how IAsyncEnumerable works with ASP.NET Web API

廉价感情. 提交于 2020-08-22 11:41:46
问题 I encountered an interesting behavior while exploring IAsyncEnumerable in an ASP.NET Web API project. Consider the following code samples: // Code Sample 1 [HttpGet] public async IAsyncEnumerable<int> GetAsync() { for (int i = 0; i < 10; i++) { await Task.Delay(1000); yield return i; } } // Code Sample 2 [HttpGet] public async IAsyncEnumerable<string> GetAsync() { for (int i = 0; i < 10; i++) { await Task.Delay(1000); yield return i.ToString(); } } Sample 1 (int array) returns {} as JSON

.net core 3.1: 'IAsyncEnumerable<string>' does not contain a definition for 'GetAwaiter'

自作多情 提交于 2020-08-09 06:19:11
问题 I have a .net core 3.1 console app. I have a method with the following signature: public async IAsyncEnumerable<string> GetFilePathsFromRelativePathAsync(string relativePath) If I call it: private async Task<IEnumerable<FileUpload>> GetFileUploadsAsync(string relativePath) { ... var filePaths = await service.GetFilePathsFromRelativePathAsync(relativePath); ... } I get the following error: Error CS1061 'IAsyncEnumerable' does not contain a definition for 'GetAwaiter' and no accessible

'AsyncEnumerableReader' reached the configured maximum size of the buffer when enumerating a value

被刻印的时光 ゝ 提交于 2020-06-23 08:25:49
问题 I am using an async/await method returning IAsyncEnumerable<> to retrieve rows from a SQL Server database and provide them via a Web API .Net Core 3.0 interface. It works fine until I exceed 8192 rows. It fails for rows beyond that point. I have tried 3 different tables, each with very different row sizes. Each time the failure occurs after yielding 8192 rows. Here is the error I see: An unhandled exception occurred while processing the request. InvalidOperationException:

Can you use IAsyncEnumerable in Razor pages to progressively display markup?

六月ゝ 毕业季﹏ 提交于 2020-06-10 16:54:50
问题 I've been playing around with Blazor and the IAsyncEnumerable feature in C# 8.0. Is it possible to use IAsyncEnumerable and await within Razor Pages to progressively display markup with data? Example service: private static readonly string[] games = new[] { "Call of Duty", "Legend of Zelda", "Super Mario 64" }; public async IAsyncEnumerable<string> GetGames() { foreach (var game in games) { await Task.Delay(1000); yield return game; } } Example in razor page: @await foreach(var game in

Can you use IAsyncEnumerable in Razor pages to progressively display markup?

社会主义新天地 提交于 2020-06-10 16:49:28
问题 I've been playing around with Blazor and the IAsyncEnumerable feature in C# 8.0. Is it possible to use IAsyncEnumerable and await within Razor Pages to progressively display markup with data? Example service: private static readonly string[] games = new[] { "Call of Duty", "Legend of Zelda", "Super Mario 64" }; public async IAsyncEnumerable<string> GetGames() { foreach (var game in games) { await Task.Delay(1000); yield return game; } } Example in razor page: @await foreach(var game in

Return IAsyncEnumerable from an async method

橙三吉。 提交于 2020-05-15 09:23:05
问题 Take the following the methods: public async IAsyncEnumerable<int> Foo() { await SomeAsyncMethod(); return Bar(); // Throws since you can not return values from iterators } public async IAsyncEnumerable<int> Bar() { for(int i = 0; i < 10; i++) { await Task.Delay(100); yield return i; } } I wonder what the best practice would be, to do, what the code above tries to. Basically returning an IAsyncEnumerable from an async method. For myself I can imagine two ways: Iterating over the

How do you mock an IAsyncEnumerable?

梦想与她 提交于 2020-05-14 18:04:46
问题 I want to unit test a method that calls another method of a service returning an IAsyncEnumerable<T> . I have created a a mock of my service Mock<MyService> and I want to setUp this mock but I don't know how to do that. Is it possible ? Are there other ways of unit testing a method that calls something retuning an IAsyncEnumerable public async Task<List<String>> MyMethodIWantToTest() { var results = new List<string>(); await foreach(var item in _myService.CallSomethingReturningAsyncStream())

How do you mock an IAsyncEnumerable?

血红的双手。 提交于 2020-05-14 18:04:06
问题 I want to unit test a method that calls another method of a service returning an IAsyncEnumerable<T> . I have created a a mock of my service Mock<MyService> and I want to setUp this mock but I don't know how to do that. Is it possible ? Are there other ways of unit testing a method that calls something retuning an IAsyncEnumerable public async Task<List<String>> MyMethodIWantToTest() { var results = new List<string>(); await foreach(var item in _myService.CallSomethingReturningAsyncStream())

Is there a C# class like Queue that implements IAsyncEnumerable?

心不动则不痛 提交于 2020-03-22 15:45:35
问题 Both Queue and ConcurrentQueue implement IEnumerable but not IAsyncEnumerable . Is there a standard class or class available on NuGet which implements IAsyncEnumerable such that, if the queue is empty, the result of MoveNextAsync does not complete until something next is added to the queue? 回答1: If you are using the .NET Core platform there are at least two built-in options: The System.Threading.Tasks.Dataflow.BufferBlock<T> class, part of the TPL Dataflow library. It doesn't implement the

How to await the results of an IAsyncEnumerable<Task<T>>, with a specific level of concurrency

风格不统一 提交于 2020-03-21 06:51:09
问题 I have an asynchronous stream of tasks, that is generated by applying an async lambda to a stream of items: IAsyncEnumerable<int> streamOfItems = AsyncEnumerable.Range(1, 10); IAsyncEnumerable<Task<string>> streamOfTasks = streamOfItems.Select(async x => { await Task.Delay(100); return x.ToString(); }) The methods AsyncEnumerable.Range and Select above are provided from the System.Linq.Async package. The result I want is a stream of results, expressed as an IAsyncEnumerable<string> . The