Using Rx to subscribe to progress event and still get result on completion
I have to call a method belonging to an external component. The signature
of the method looks something like this:
IImportedData Import(string fileName, Action<int> progress);
This operation can take a long time to execute, so I need to call it
asynchronously and report progress to the user. I'm looking at different
approaches to calling it (Rx, TPL, ThreadPool) to find something
expressive and clear, however I'm struggling to come up with a way to do
it in Rx.
At first glace, the idea of reporting progress using Rx seems like a
perfect fit - it's a stream of incoming ints relating to progress. The
only catch is that when the operation completes, I need to inspect
IImportedData to display a result to the user. OnCompleted isn't intended
for that purpose, which leads me down a path of having a class that
exposes two IObservable streams, and then a method to "Start" the
operation.
private class Importer : IObservable<int>, IObservable<IImportedData>
Feels clunky and I'm sure there's a better way that I don't know of. Any
advice appreciated :)
Thanks
No comments:
Post a Comment