Add support for IAsyncEnumerable
DorianGreen opened this issue · comments
Dorian Green commented
Right now, in order to return an IAsyncEnumerable you need to use EndpointBaseSync and access the request cancellationToken form HttpContext like this:
public class List : EndpointBaseSync.WithoutRequest.WithResult<IAsyncEnumerable<PropertyListResult>>
{
/// <summary>
/// List all Properties
/// </summary>
[HttpGet("api/[namespace]")]
public override async IAsyncEnumerable<PropertyListResult> Handle()
{
var cancellationToken = HttpContext.RequestAborted;
await Task.CompletedTask;
yield break;
}
}
It would be nice if we could do something like this:
public class List : EndpointBaseAsync.WithoutRequest.WithAsyncEnumerableResult<PropertyListResult>
{
/// <summary>
/// List all Properties
/// </summary>
[HttpGet("api/[namespace]")]
public override async IAsyncEnumerable<PropertyListResult> Handle(CancellationToken cancellationToken = default)
{
await Task.CompletedTask;
yield break;
}
}
Tobias Haimerl commented
See also jbogard/MediatR#574 (comment) as a reference for the needed targetframework changes.
Tobias Haimerl commented
Tobias Haimerl commented
Feature is now in main.
Issue can be closed <3
AlexanderFinkbeiner commented
is the only thing missing, a new nuget version?
Steve Smith commented
I guess it has been a while...
AlexanderFinkbeiner commented