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

37 lines
1.5 KiB
JavaScript
Raw Normal View History

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