Is there a way to subscribe an observer as async

前端 未结 3 556
离开以前
离开以前 2021-01-07 00:18

Given a synchronous observer, is there a way to do this:

observable.SubscribeAsync(observer);

And have all methods on the observer

3条回答
  •  渐次进展
    2021-01-07 00:22

    If by having the methods on the observer called asynchronously, you mean that you want a situation where a new notification can be published without waiting for handling of the previous notification to complete, then this is something you will have to do yourself. This breaks the contract of Rx, because if you can have multiple notifications in flight at the same time, you can no longer guarantee that notifications are processed in order. I think there are also other concerns with this approach - it's something you'll want to be careful about.

    On the other hand, if you simply want to handle notifications on a different thread from the one that created the notifications, then ObserveOn and SubscribeOn are what you want to look into.

提交回复
热议问题