-
Notifications
You must be signed in to change notification settings - Fork 3k
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(audit, auditTime): audit and auditTime emit last value after source completes #5799
Changes from all commits
d8c40fa
fae75ed
6d66de8
b5f9368
ca4a7cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ export function audit<T>(durationSelector: (value: T) => SubscribableOrPromise<a | |
let hasValue = false; | ||
let lastValue: T | null = null; | ||
let durationSubscriber: Subscriber<any> | null = null; | ||
let isComplete = false; | ||
|
||
const endDuration = () => { | ||
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. @cartant, do we want to fix the duration notifier treating completion like a notification here? Or shall we get that at a later time? The whole thing is weird. Like 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. Yeah, we should fix it. Whether it's fixed here or someplace else, I don't mind. I intend to do another pass through all of the operators that take a notifier to make sure their behaviour is consistent, etc. |
||
durationSubscriber?.unsubscribe(); | ||
|
@@ -66,18 +67,27 @@ export function audit<T>(durationSelector: (value: T) => SubscribableOrPromise<a | |
lastValue = null; | ||
subscriber.next(value); | ||
} | ||
isComplete && subscriber.complete(); | ||
}; | ||
|
||
source.subscribe( | ||
new OperatorSubscriber(subscriber, (value) => { | ||
hasValue = true; | ||
lastValue = value; | ||
if (!durationSubscriber) { | ||
innerFrom(durationSelector(value)).subscribe( | ||
(durationSubscriber = new OperatorSubscriber(subscriber, endDuration, undefined, endDuration)) | ||
); | ||
new OperatorSubscriber( | ||
subscriber, | ||
(value) => { | ||
hasValue = true; | ||
lastValue = value; | ||
if (!durationSubscriber) { | ||
innerFrom(durationSelector(value)).subscribe( | ||
(durationSubscriber = new OperatorSubscriber(subscriber, endDuration, undefined, endDuration)) | ||
); | ||
} | ||
}, | ||
undefined, | ||
() => { | ||
isComplete = true; | ||
(!hasValue || !durationSubscriber || durationSubscriber.closed) && subscriber.complete(); | ||
} | ||
}) | ||
) | ||
); | ||
}); | ||
} |
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.
Hmmm... I'll need to think about this. I think this makes the most sense. Given that there are items to audit, and we're waiting for a duration that just never arrives... But I want a second opinion: @cartant
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.
Yeah, I think this makes sense, too. Above all, the behaviour needs to be consistent between operators and, AFAICT,
delayWhen
doesn't complete if its notifier isNEVER
:rxjs/spec/operators/delayWhen-spec.ts
Lines 131 to 144 in 0d3094f
So this LGTM.