Skip to content

Commit

Permalink
Update order of invocation in sendNext: RACReplaySubject
Browse files Browse the repository at this point in the history
valuesReceived should be cleaned up before sending value.

If we have subscription and creating another subscription on the same RACReplaySubject while -take:1 it - we can get first value instead of second.
  • Loading branch information
Aleksei Minaev authored Mar 14, 2019
1 parent a621018 commit 74ab5ba
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ReactiveObjC/RACReplaySubject.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ - (RACDisposable *)subscribe:(id<RACSubscriber>)subscriber {
- (void)sendNext:(id)value {
@synchronized (self) {
[self.valuesReceived addObject:value ?: RACTupleNil.tupleNil];
[super sendNext:value];

if (self.capacity != RACReplaySubjectUnlimitedCapacity && self.valuesReceived.count > self.capacity) {
[self.valuesReceived removeObjectsInRange:NSMakeRange(0, self.valuesReceived.count - self.capacity)];
}

[super sendNext:value];
}
}

Expand Down

0 comments on commit 74ab5ba

Please sign in to comment.