TPL vs Reactive Framework

后端 未结 5 1122
礼貌的吻别
礼貌的吻别 2020-12-13 12:39

When would one choose to use Rx over TPL or are the 2 frameworks orthogonal?

From what I understand Rx is primarily intended to provide an abstraction over events an

5条回答
  •  误落风尘
    2020-12-13 13:08

    The main purpose of Rx is not to provide an abstraction over events. This is just one of its outcomes. Its primary purpose is to provide a composable push model for collections.

    The reactive framework (Rx) is based on IObservable being the mathematical dual of IEnumerable. So rather than "pull" items from a collection using IEnumerable we can have objects "pushed" to us via IObservable.

    Of course, when we actually go looking for observable sources things like events & async operations are excellent candidates.

    The reactive framework naturally requires a multi-threaded model to be able to watch the sources of observable data and to manage queries and subscriptions. Rx actually makes heavy use of the TPL to do this.

    So if you use Rx you are implicitly using the TPL.

    You would use the TPL directly if you wish direct control over your tasks.

    But if you have sources of data that you wish to observe and perform queries against then I thoroughly recommend the reactive framework.

提交回复
热议问题