I'm trying to wrap an asynchronous subscription API based on events with an API based on IAsyncEnumerable
. Basically along the lines of:
async IAsyncEnumerable<string> ReadAll()
{
var reader = new EventBasedReader();
reader.OnRead => (_, args) => yield return e.Message;
reader.Start();
await reader.WaitUntilAllRead();
}
However this doesn't work because it's the event handler that yields, and this isn't allowed. Is there another way I can write this to make it work as an IAsyncEnumerable
?