开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜