For this example I’m going to use a Console application and hit an OData endpoint.

First we are going to create a class that will query the OData endpoint figure out how many calls we need to make then return back an array of Tasks. The method signature looks a little funky because OData Task returns back an IEnumberable<T>.

Now in our console application we will convert the task into IObservables and process them when they come in.

private static void Main(string[] args)
{
var task = Task.Run(async () =>
{
var uri =
new Uri("http://services.odata.org/AdventureWorksV3/AdventureWorks.svc/");
var client = new CombineOData(uri);
// products is an array of task that return IEnumerables.
var productsTasks = await client.GetData("ProductCatalog");
// convert the task to observable
// then merge them into one observable
// then make the IEnumberable into an observable
var products = productsTasks.Select(p => p.ToObservable())
.Merge()
.SelectMany(t => t.ToObservable());
// want to IConnectable because we will subscribe twice one for the result and await for the results to be done
var publisher = products.Publish();
// just log to the console window to view the results as they come in to prove it's processing it as they arrive
publisher.Subscribe(
catalog => Console.WriteLine("{0} {1} {2} {3}", catalog.ID, catalog.ProductID, catalog.ProductName,
catalog.ProductNumber),
ex => Console.WriteLine(ex.Message),
() => Console.WriteLine("Completed"));
// Don't continue past this point until the observable is complete
// this will also auto connect the publisher and start the process
var data = await publisher;
// proof that we didn't hit this line until afterwards
Console.WriteLine("After await {0}", data.ID);
});
Console.ReadKey();
}

The real key is to switch the task ToObservable and the merge to make them one sequence. From that we just needed to publish so we can have our method await for it to finish.