分类
通过期权赚钱的最佳方式

怎么处理冷信号与热信号

在RAC 2的术语中,“冷”RACSignal对每个订阅执行一次工作。换言之,冷信号在调用-subscribe…方法时会产生副作用,如果调用返回的方法-dispose,则可能会取消正在进行的工作。 此模式非常有用,因为它可以最大限度地减少不必要的工作,并允许take、retry、concat等操作员在工作开始和取消时进行操作。冷信号也类似于未来和承诺的工作方式,可以用于构造异步代码(如网络请求)。

反应可可中的热信号和冷信号有哪些示例?

在RAC 2的术语中,“热”RAC信号在调用-subscribe…方法时不会触发任何副作用。换句话说,热信号完全是生产者驱动和推送式的,消费者(订户)不会对其生命周期产生任何影响。

此模式对于通知观察者无论发生什么情况都将发生的事件非常有用。例如,加载布尔值可能会在true和false之间切换,而不管是否有任何对象正在观察它。

具体地说,每个RACSubject都是一种热信号,因为转发的事件不是由subject上的订户数量决定的。

冷信号现在是信号发生器

在RAC 2的术语中,“冷”RACSignal对每个订阅执行一次工作。换言之,冷信号在调用-subscribe…方法时会产生副作用,如果调用返回的方法-dispose,则可能会取消正在进行的工作。

此模式非常有用,因为它可以最大限度地减少不必要的工作,并允许take、retry、concat等操作员在工作开始和取消时进行操作。冷信号也类似于未来和承诺的工作方式,可以用于构造异步代码(如网络请求)。

What are examples of hot and cold 怎么处理冷信号与热信号 signal in ReactiveCocoa?

Question

In this answer How to make RACSignal to become hot?, @erikprice explains hot and cold 怎么处理冷信号与热信号 signal

A "hot signal" is a signal that sends values (and presumably does work) regardless of whether it has any subscribers. A "cold signal" is a signal that defers its work and the sending of any values until it has a subscriber. And a cold signal will perform its work and send values for 怎么处理冷信号与热信号 each subscriber.

I ask if someone can demonstrate examples of hot and cold 怎么处理冷信号与热信号 signals, so that it will be clearer

Answers

I find the RAC 3 Changelog to be useful, too

Hot signals are now Signals

In the terminology of RAC 2, a “hot” RACSignal does not trigger any side effects when a -subscribe… method is called upon it. In other words, hot signals are entirely producer-driven and push-based, and consumers (subscribers) cannot have any effect on their lifetime.

This pattern is useful for notifying observers about events that will occur no matter what. For 怎么处理冷信号与怎么处理冷信号与热信号 热信号 example, a loading boolean might flip between true and false regardless of whether anything is observing it.

Concretely, every 怎么处理冷信号与热信号 RACSubject is a kind of hot signal, because the events being forwarded are not determined by the number of subscribers on the subject.

Cold signals are now SignalProducers

In the terminology of RAC 2, a “cold” 怎么处理冷信号与热信号 怎么处理冷信号与热信号 RACSignal performs its work one time for every subscription. In other words, cold signals perform side effects when a -subscribe… method is called upon them, and may be able to cancel in-progress work if -dispose is called upon the returned RACDisposable.

This pattern is broadly useful because it minimizes unnecessary work, and allows operators like take, retry, concat, etc. to manipulate when work is started and cancelled. Cold signals are 怎么处理冷信号与热信号 also similar to how futures and promises work, and can be useful for structuring asynchronous code (like network requests).

I have written Push vs Pull Signal which basically reveal how Push vs Pull Signal get implemented, in Swift 2