wishthis/node_modules/rxjs/dist/esm5/internal/operators/audit.js
2022-06-08 12:36:39 +02:00

37 lines
No EOL
1.5 KiB
JavaScript

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