ReactiveCocoa 中冷热信号的例子有哪些?
What are examples of hot and cold signal in ReactiveCocoa?
在这个回答 How to make RACSignal to become hot? 中,@erikprice 解释了冷热信号
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.
请问有没有人能演示一下冷热信号的例子,这样会更清楚
A hot signal is considered to be a signal that sends values regardless of whether it has any subscribers
我正在使用热信号来监控网络可达性。通过RACCommand
实现的按钮动作是热信号的另一个例子。
A "cold signal" is a signal that defers its work and the sending of any values until it has a subscriber.
通过使 AFNetworking 具有反应性,可以很好地证明这一点。创建一个 returns 表示请求的信号的方法。每当您订阅该信号时,都会执行网络请求。订阅者在请求成功时为 sendNext:
和 sendCompleted
,在请求失败时为 sendError:
。
我发现 RAC 3 Changelog 也很有用
热门信号现在是信号
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.
冷信号现在是 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).
我在 Swift 2
中写了 Push vs Pull Signal,它基本上揭示了推信号与拉信号是如何实现的
在这个回答 How to make RACSignal to become hot? 中,@erikprice 解释了冷热信号
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.
请问有没有人能演示一下冷热信号的例子,这样会更清楚
A hot signal is considered to be a signal that sends values regardless of whether it has any subscribers
我正在使用热信号来监控网络可达性。通过RACCommand
实现的按钮动作是热信号的另一个例子。
A "cold signal" is a signal that defers its work and the sending of any values until it has a subscriber.
通过使 AFNetworking 具有反应性,可以很好地证明这一点。创建一个 returns 表示请求的信号的方法。每当您订阅该信号时,都会执行网络请求。订阅者在请求成功时为 sendNext:
和 sendCompleted
,在请求失败时为 sendError:
。
我发现 RAC 3 Changelog 也很有用
热门信号现在是信号
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.
冷信号现在是 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).
我在 Swift 2
中写了 Push vs Pull Signal,它基本上揭示了推信号与拉信号是如何实现的