I am playing around with OneOf (https://github.com/mcintyre321/OneOf) nuget package, but I was wondering can I use it with IAsyncEnumerable operations so I camu up sith this little monster:
private async Task<OneOf<IAsyncEnumerable<string>, TypeNotFoundException>> AsyncTry()
{
async Task<string> GetMessage(int n)
{
await Task.Delay(1000);
return $"Message #{n}";
}
async IAsyncEnumerable<string> GetMessages(int max)
{
for (var i = 1; i <= max; i++)
{
var message = await GetMessage(i);
yield return message;
}
}
IAsyncEnumerable<string> enumerable = GetMessages(30);
await foreach (var message in enumerable)
{
yield return message;
}
return new TypeNotFoundException("Undefined response type");
}
Problem is it does not accept it, so is this can be done?