I have a Web API like this:
- it calls the
IService.Get
method which returns anIAsyncEnumerable<>
data - the
Get
method will return a success/failure indicator - it returns the individual item and accumulate the success/failure numbers
- finally it return an object that contains the success and failure count
Code:
app.MapGet("/api/data", ([FromServices] IService s, CancellationToken cancellationToken) =>
{
return Func();
async IAsyncEnumerable<dynamic> Func()
{
var success = 0;
var fail = 0;
await foreach (var x in s.Get(cancellationToken))
{
if (x.Item1)
success++;
else
fail++;
yield return new { success = x.Item1, id = x.Item2 };
}
yield return new { success, fail };
}
});
I have already get the code inside the IService.Get
to be very reactive. But I am stuck at the final step.
In the API, I need to:
- return the raw data from
Get
- accumulate and transform the raw data and return the final result
What reactive function could do this?