开发者

Is there an equivalent of the Task.ContinueWith operator in Rx?

开发者 https://www.devze.com 2023-03-21 05:31 出处:网络
Is there an equivalent of the Task.ContinueWith operator in Rx? I\'m using Rx with Silverlight,I am making two webservice calls with the FromAsyncPattern method, and I\'d like to do them synchronousl

Is there an equivalent of the Task.ContinueWith operator in Rx?

I'm using Rx with Silverlight, I am making two webservice calls with the FromAsyncPattern method, and I'd like to do them synchronously.

        var o1 = Observable.FromAsyncPattern<int, string>(client.BeginGetData, client.EndGetData);
        var o2 = Observable.FromAsyncPattern<int, string>(client.BeginGetData, client.EndGetData);
开发者_StackOverflow

Is there an operator (like Zip) that will only start / subscribe to o2 only after o1 returns Completed?

I handle failure of either web service call the same way.


Yes, it's called projection:

o1().SelectMany(_ => o2()).Subscribe();


While Alex is right, the other way you can do this is:

Observable.Concat(
    o1(4),
    o2(6))
  .Subscribe(x => /* Always one, then two */);

Which guarantees that o2 only runs after o1 - as opposed to Merge, which would run them at the same time:

Observable.Merge(
    o1(4),
    o2(6))
  .Subscribe(x => /* Either one or two */);
0

精彩评论

暂无评论...
验证码 换一张
取 消