wishthis/node_modules/rxjs/dist/esm5/internal/operators/audit.js

37 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-04-07 07:06:43 +00:00
import { operate } from '../util/lift';
import { innerFrom } from '../observable/innerFrom';
import { createOperatorSubscriber } from './OperatorSubscriber';
export function audit(durationSelector) {
return operate(function (source, subscriber) {
var hasValue = false;
var lastValue = null;
var durationSubscriber = null;
var isComplete = false;
var endDuration = function () {
durationSubscriber === null || durationSubscriber === void 0 ? void 0 : durationSubscriber.unsubscribe();
durationSubscriber = null;
if (hasValue) {
hasValue = false;
var value = lastValue;
lastValue = null;
subscriber.next(value);
}
isComplete && subscriber.complete();
};
var cleanupDuration = function () {
durationSubscriber = null;
isComplete && subscriber.complete();
};
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
hasValue = true;
lastValue = value;
if (!durationSubscriber) {
innerFrom(durationSelector(value)).subscribe((durationSubscriber = createOperatorSubscriber(subscriber, endDuration, cleanupDuration)));
}
}, function () {
isComplete = true;
(!hasValue || !durationSubscriber || durationSubscriber.closed) && subscriber.complete();
}));
});
}
//# sourceMappingURL=audit.js.map