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

纵然是瞬间 提交于 2019-12-10 09:32:00

问题


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);

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.


回答1:


Yes, it's called projection:

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



回答2:


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 */);


来源:https://stackoverflow.com/questions/6753482/is-there-an-equivalent-of-the-task-continuewith-operator-in-rx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!