How can a buffered replay subject be implemented in ReactiveSwift?
I've looked at replayLazily(upTo:)
operator of SignalProducer
, and also the pipe()
function of the Signal
type, however I can't see a straightforward way of creating something equivalent to Rx ReplaySubject
.
This brings up the following questions as well:
ReactiveSwift implements Subject
with Signal.pipe()
, however you can't specify a buffer for the pipe the same way you can for a Rx ReplaySubject. Are there any workarounds?
replayLazily(upTo:)
operator is missing from the Signal
type. I guess this is not so bad since you can create a SignalProducer
from a Signal
. But why does Signal
not have the same operator?
Has anyone encountered this problem before? Or am I missing something?
Any help would be much appreciated.
The Signal
docs say:
An observer of a Signal will see the exact same sequence of events as all other observers. In other words, events will be sent to all observers at the same time.
This is in contrast to producers, which create a new signal each time they are started, which means it's possible for each observer to see different events.
The buffering scenario requires each observer to receive a list of current values in the buffer upon subscription, and other observers should not receive these values each time a new observer is added. Therefore, each observer needs their own signal, and that means the buffering mechanism must be implemented as a producer which can create a new signal for each subscriber.
There's a good discussion from 2016 when replayLazily
was added that hopefully clarifies the thinking behind the operator and why it absolutely can't be a part of Signal
.