I\'ve seen tons of examples on how to use the Observable.FromAsyncPattern() in the Rx Framework to simplify Async calls, but I\'m using an interface that doesn\'t use the st
I like Observable.Create for this, but @dahlbyk answer is incorrect(misses completion and performs the action in the unsubscribe handler). Should be something like this:
IObservable> FromListCallbackPattern(
Action>> listGetter)
{
return Observable
.Create>(observer =>
{
var subscribed = true;
listGetter(list =>
{
if (!subscribed) return;
observer.OnNext(list);
observer.OnCompleted();
});
return () =>
{
subscribed = false;
};
});
}
Also, since the originating API returns an entire list altogether, I don't see a reason to transform it to observable too early. Let the resulting observable return a list as well, and if a caller needs to flatten it, he can use .SelectMany