我已经遇到了需要直接控制"process in subscription order"之前的场景 . 在这种情况下,我需要've used a simple function to turn one observable into two, one of which is guaranteed to be notified before the other. You could use a similar method to avoid making the assumption that subscriptions will always be processed in order, though I personally do not think it' . 如果有兴趣,可以在这里找到详细信息:RxJs: Drag and Drop example : add mousedragstart
-1
就 behaviorSubject 和一般的主题而言,它们是"Hot"生成和消费 Value 的观察者 . 您可以假设只要没有调用 observer.complete() 方法,下一个函数将始终触发 .
2 回答
实际上,是的,这是安全的;
Subject
类(从中继承BehaviorSubject
)的实现始终按照获取顺序处理订阅 . 虽然我没有看到rxjs团队保证这种情况总是如此,但我想改变这会破坏很多代码(包括我的代码) .严格来说,不,不保证订阅处理订单 . 这可以追溯到.NET下的Rx,当团队试图将订阅行为与多播代表的行为对齐时(你可以在https://social.msdn.microsoft.com/Forums/en-US/ac721f91-4dbc-40b8-a2b2-19f00998239f/order-of-subscriptions-order-of-observations?forum=rx找到Bart De Smet的一个很好的解释) .
我已经遇到了需要直接控制"process in subscription order"之前的场景 . 在这种情况下,我需要've used a simple function to turn one observable into two, one of which is guaranteed to be notified before the other. You could use a similar method to avoid making the assumption that subscriptions will always be processed in order, though I personally do not think it' . 如果有兴趣,可以在这里找到详细信息:RxJs: Drag and Drop example : add mousedragstart
就
behaviorSubject
和一般的主题而言,它们是"Hot"生成和消费 Value 的观察者 . 您可以假设只要没有调用observer.complete()
方法,下一个函数将始终触发 .您拥有的第一个订阅将设置并初始化状态(此处为假设),因此每个后续订阅者都可以挂接到该订阅并确定
next(value)
发射 .希望这可以帮助 .