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
Fix 6805: remove strange groupBy behavior #7252
Merged
benlesh
merged 2 commits into
ReactiveX:master
from
benlesh:fix-6805_remove-strange-groupBy-behavior
May 15, 2023
Merged
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
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
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ import { Observable } from '../Observable'; | |
import { from } from '../observable/from'; | ||
import { Subject } from '../Subject'; | ||
import { ObservableInput, Observer, OperatorFunction, SubjectLike } from '../types'; | ||
import { createOperatorSubscriber, OperatorSubscriber } from './OperatorSubscriber'; | ||
import { createOperatorSubscriber } from './OperatorSubscriber'; | ||
|
||
export interface BasicGroupByOptions<K, T> { | ||
element?: undefined; | ||
|
@@ -165,20 +165,14 @@ export function groupBy<T, K, R>( | |
// next call from the source. | ||
const handleError = (err: any) => notify((consumer) => consumer.error(err)); | ||
|
||
// The number of actively subscribed groups | ||
let activeGroups = 0; | ||
|
||
// Whether or not teardown was attempted on this subscription. | ||
let teardownAttempted = false; | ||
|
||
// Capturing a reference to this, because we need a handle to it | ||
// in `createGroupedObservable` below. This is what we use to | ||
// subscribe to our source observable. This sometimes needs to be unsubscribed | ||
// out-of-band with our `subscriber` which is the downstream subscriber, or destination, | ||
// in cases where a user unsubscribes from the main resulting subscription, but | ||
// still has groups from this subscription subscribed and would expect values from it | ||
// Consider: `source.pipe(groupBy(fn), take(2))`. | ||
const groupBySourceSubscriber = new OperatorSubscriber( | ||
const groupBySourceSubscriber = createOperatorSubscriber( | ||
subscriber, | ||
(value: T) => { | ||
// Because we have to notify all groups of any errors that occur in here, | ||
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. GH didn't allow me to put a comment in the exact spot lines 189-191 here but I think the comment also needs revisiting as the mentioned reference counting seem to be removed now. |
||
|
@@ -240,14 +234,7 @@ export function groupBy<T, K, R>( | |
// When the source subscription is _finally_ torn down, release the subjects and keys | ||
// in our groups Map, they may be quite large and we don't want to keep them around if we | ||
// don't have to. | ||
() => groups.clear(), | ||
() => { | ||
teardownAttempted = true; | ||
// We only kill our subscription to the source if we have | ||
// no active groups. As stated above, consider this scenario: | ||
// source$.pipe(groupBy(fn), take(2)). | ||
return activeGroups === 0; | ||
} | ||
() => groups.clear() | ||
); | ||
|
||
// Subscribe to the source | ||
|
@@ -259,17 +246,7 @@ export function groupBy<T, K, R>( | |
* @param groupSubject The subject that fuels the group | ||
*/ | ||
function createGroupedObservable(key: K, groupSubject: SubjectLike<any>) { | ||
const result: any = new Observable<T>((groupSubscriber) => { | ||
activeGroups++; | ||
const innerSub = groupSubject.subscribe(groupSubscriber); | ||
return () => { | ||
innerSub.unsubscribe(); | ||
// We can kill the subscription to our source if we now have no more | ||
// active groups subscribed, and a finalization was already attempted on | ||
// the source. | ||
--activeGroups === 0 && teardownAttempted && groupBySourceSubscriber.unsubscribe(); | ||
}; | ||
}); | ||
const result: any = new Observable<T>((groupSubscriber) => groupSubject.subscribe(groupSubscriber)); | ||
result.key = key; | ||
return result; | ||
} | ||
|
Oops, something went wrong.
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.
Revisit this comment.