在RX中,处理线程安全是消费者(IOBSERVER)的责任吗?
在Reactivex范式中,是消费者的责任(iObserver
)来处理线程安全吗?
例如,如果on Completed
呼叫在onNext
仍在另一个线程上执行时会出现吗?
它看起来像从rx .net源中,但是文档有些模糊。
In ReactiveX paradigm, Is it a responsibility of the consumer (IObserver
) to deal with thread safety?
E.g., if OnCompleted
call comes along when OnNext
is still executing on another thread?
It looks like it from Rx .NET sources but the docs are somewhat vague.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于我最初在a
似乎我假设线程安全序列化是消费者的责任(
iobserver
)。根据原始 RX设计指南文档(看起来是最佳的秘密:)
更远:
最后:
我个人的看法:如果产生
iObservable
的原始序列可以在调用onNext
,onerror
,oncomplete >(或当
处置时,请在其订阅中调用),应该注意正确地序列化这些呼叫。Since I initially asked this question in a tweet, I believe I've now found an authoritative answer.
It appears I was wrong in my assumption that thread-safe serialization is the consumer's responsibility (
IObserver
).According to the original Rx Design Guidelines document (a best-kept secret as it seems :)
Further:
And finally:
My personal take from this: if an original sequence producing
IObservable
can introduce parallelism when it callsOnNext
,OnError
,OnComplete
(or whenDispose
is called on its subscription), it should take care to serialize these calls properly.