ReactiveCocoa / ReactiveObjC

The 2.x ReactiveCocoa Objective-C API: Streams of values over time
MIT License
2.6k stars 494 forks source link

Update order of invocation in -sendNext: RACReplaySubject #154

Closed zulkis closed 5 years ago

zulkis commented 5 years ago

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.

RACReplaySubject *subject = [RACReplaySubject replaySubjectWithCapacity:1];
        [subject subscribeNext:^(id  _Nullable item1) {
            NSLog(@"%@", item1);
            [[subject take:1] subscribeNext:^(id  _Nullable item2) {
                NSLog(@"%@", item2);
            }];
        }];
        [subject sendNext:@"first"];
        [subject sendNext:@"second"];

Expected:

first first second second

Got:

first first second first

mdiep commented 5 years ago

That seems reasonable. Can you add a test?

zulkis commented 5 years ago

Will do. Still, I am not sure why one MR check is failing because of some validation error. Any advice on it?

mdiep commented 5 years ago

Things look good here. Thanks!