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
Func> FromListCallbackPattern(Action>> function)
{
return () => {
// We use a ReplaySubject so that if people subscribe *after* the
// real method finishes, they'll still get all the items
ret = new ReplaySubject();
function((list) => {
// We're going to "rebroadcast" the list onto the Subject
// This isn't the most Rx'iest way to do this, but it is the most
// comprehensible :)
foreach(var v in list) {
ret.OnNext(v);
}
ret.OnCompleted();
});
return ret;
};
}
Now, you can do something like:
var getAllUsers = FromListCallbackPattern(mClient.GetAllUsers);
getAllUsers().Subscribe(x => /* ... */);