One way to buffer values is to use -[RACSignal collect]
, which collects them into an array until the signal completes:
[[[RACSignal combineLatest:@[ s1, s2, s3 ]]
collect]
takeUntil:s4]
Howevever, you probably wanted each value to be sent individually on the final signal, not an array of values. You can use -[RACSignal flattenMap:]
to flatten those values back into the final signal:
[[[[RACSignal combineLatest:@[ s1, s2, s3 ]]
collect]
takeUntil:s4]
flattenMap:^(NSArray *collected) {
return [[collected rac_sequence] signal];
}]
And since you don't want your signal to be completed after s4
, you can use -repeat
to resubscribe after every time s4
sends a value. If you didn't do this, the -takeUntil:
would cause your signal to complete when that happens.
[[[[[RACSignal combineLatest:@[ s1, s2, s3 ]]
collect]
takeUntil:s4]
flattenMap:^(NSArray *collected) {
return [[collected rac_sequence] signal];
}]
repeat]
Note that if any of the combined signals are cold signals, the resubscription will cause their side effects to occur additional times. So you may have to convert them into a hot signal by multicasting them (or the combined signal):
RACMulticastConnection *mc = [[RACSignal combineLatest:@[ s1, s2, s3 ]] publish];
RACDisposable *d = [mc connect];
[[[mc.signal
takeUntil:s4]
flattenMap:^(NSArray *collected) {
return [[collected rac_sequence] signal];
}]
repeat]
You may need to explicitly unsubscribe (by disposing d
) if your signal would otherwise live infinitely.
(Nota bene, this code is untested.)