New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flatten changes #2976
Closed
Closed
Flatten changes #2976
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1907,6 +1907,61 @@ + (void)configure:(Configuration *)configuration { | |
expect(@(flattenDisposable.disposed)).toEventually(beTruthy()); | ||
} | ||
}); | ||
|
||
qck_it(@"only subscribes to one signal at a time - even when adding new signals at the same time as one completes", ^{ | ||
for (int i = 0; i < 100; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not wild about adding a long test like this. 😕 It takes 1.6s on CI. |
||
dispatch_semaphore_t ready1 = dispatch_semaphore_create(0); | ||
dispatch_semaphore_t ready2 = dispatch_semaphore_create(0); | ||
dispatch_semaphore_t barrier1 = dispatch_semaphore_create(0); | ||
dispatch_semaphore_t barrier2 = dispatch_semaphore_create(0); | ||
subscribedTo1 = NO; | ||
subscribedTo2 = NO; | ||
subscribedTo3 = NO; | ||
|
||
RACDisposable *flattenDisposable = [[signalsSubject flatten:1] subscribeNext:^(id x) { | ||
}]; | ||
|
||
[signalsSubject sendNext:sub1]; | ||
[signalsSubject sendNext:sub2]; | ||
|
||
expect(@(subscribedTo1)).to(beTruthy()); | ||
expect(@(subscribedTo2)).to(beFalsy()); | ||
expect(@(subscribedTo3)).to(beFalsy()); | ||
|
||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ | ||
dispatch_semaphore_signal(ready1); | ||
dispatch_semaphore_wait(barrier1, DISPATCH_TIME_FOREVER); | ||
[subject1 sendCompleted]; | ||
}); | ||
|
||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ | ||
dispatch_semaphore_signal(ready2); | ||
dispatch_semaphore_wait(barrier2, DISPATCH_TIME_FOREVER); | ||
[signalsSubject sendNext:sub3]; | ||
}); | ||
|
||
dispatch_semaphore_wait(ready1, DISPATCH_TIME_FOREVER); | ||
dispatch_semaphore_wait(ready2, DISPATCH_TIME_FOREVER); | ||
|
||
// Try to complete one signal and add a new signal | ||
// very, very shortly after | ||
dispatch_semaphore_signal(barrier1); | ||
dispatch_semaphore_signal(barrier2); | ||
|
||
// The race condition allows the just added signal to | ||
// immediately get subscribed to - see that the third signal | ||
// doesn't get that subscription yet. | ||
expect(@(subscribedTo2)).toEventually(beTruthy()); | ||
expect(@(subscribedTo3)).to(beFalsy()); | ||
|
||
[subject2 sendCompleted]; | ||
expect(@(subscribedTo3)).toEventually(beTruthy()); | ||
|
||
[subject3 sendCompleted]; | ||
|
||
[flattenDisposable dispose]; | ||
} | ||
}); | ||
}); | ||
|
||
qck_describe(@"-switchToLatest", ^{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this works generally. It works for
-concat
becausemaxConcurrent
is1
, butflatten:
needs to handlen
—includingn
pending subscriptions.Think of the case where a signal is
flatten:10
. If 3 threads race to send a signal through theflatten:
, all 3 should be immediately subscribed to—even if one of them ispendingSubscription
.So I think
pendingSubscription
should be anNSUInteger
of pending subscriptions, and this should checkmaxConcurrent > 0 || (activeDisposables.count + pendingSubscriptions >= maxConcurrent)
. Or maybe it would be simpler to add aactiveCount
and use/manipulate that instead.This is probably relatively uncommon—
flatten:
didn't seem to be widely used. But it could lead to some bad behavior.