Hi,
I want to concatenate the outputs of several async methods into a single source
I am writing several APIs that will parse data from 3rd party sources and return a standard typed item.
I played with the idea of firing events for each item but it appears that each API could potentially yield many (maybe thousands) of items in any single moment (but not continuously).
I now have the task of implementing async methods that yield Enumerable<item> continuously. I haven't implemented async before but there's plenty of tutorials out there.
I would like to have all of these results concatenated into a single source which I will then be able to adapt my awesome Reactive Extension code to,
but I don't know how to do that >_<
I tried this:
public IEnumerable<FlightData> GetFlighData()
{
var trackers = TrackerApiLoader.LoadAsyncTrackers();
return trackers.SelectMany(t => t.GetDataMethod());
}
I haven't implemented the async / await methods yet but the above code only seems to get data from the first assembly in the list of trackers.
My tracker apis are just returning test data atm.
What is the correct way to get this working?
Thanks ^_^
Update:
Perhaps this will give a better idea of what I am trying to achieve :
public IEnumerable<FlightData> GetFlighData()
{
AsyncTracker messageQueue = TrackerApiLoader.LoadMessageQueue();
IEnumerable<AsyncTracker> trackers = TrackerApiLoader.LoadAsyncTrackers();
IObservable<IEnumerable<FlightData>> ob = messageQueue.GetFlighDataMethod().ToObservable();
trackers.ToList().ForEach(t =>
{
ob.Merge(t.GetFlighDataMethod().ToObservable());
});
IObservable<FlightData> obs = ob.SelectMany(fd =>
{
var enumerable = fd as FlightData[] ?? fd.ToArray();
return enumerable;
});
If I could yield the results, that'd be great, but I can't do this! >_<
obs.Subscribe(delegate(FlightData data) { yield return data; });
yield break;
}