I have two methods connected to two different sources of Foos which return two IAsyncEnumerable<Foo>. I need to fetch all Foos from both sources before being able to process them .
Problem : I would like to query both sources simultaneously (asynchronously), ie. not waiting for Source1 to complete the enumeration before starting to enumerate Source2. From my understanding, this is what happens into the method SequentialSourcesQuery example below, am I right?
With regular tasks, I would just start the first Task, then the second one, and call a await Task.WhenAll. But I am a bit confused on how to handle IAsyncEnumerable.
public class FoosAsync
{
public async IAsyncEnumerable<Foo> Source1() { }
public async IAsyncEnumerable<Foo> Source2() { }
public async Task<List<Foo>> SequentialSourcesQuery()
{
List<Foo> foos = new List<Foo>();
await foreach (Foo foo1 in Source1())
{
foos.Add(foo1);
}
await foreach (Foo foo2 in Source2())
{ //doesn't start until Source1 completed the enumeration?
foos.Add(foo2);
}
return foos;
}
}