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

26 lines
984 B
JavaScript
Raw Normal View History

2022-06-08 10:36:39 +00:00
import { operate } from '../util/lift';
import { createOperatorSubscriber } from './OperatorSubscriber';
export function refCount() {
return operate(function (source, subscriber) {
var connection = null;
source._refCount++;
var refCounter = createOperatorSubscriber(subscriber, undefined, undefined, undefined, function () {
if (!source || source._refCount <= 0 || 0 < --source._refCount) {
connection = null;
return;
}
var sharedConnection = source._connection;
var conn = connection;
connection = null;
if (sharedConnection && (!conn || sharedConnection === conn)) {
sharedConnection.unsubscribe();
}
subscriber.unsubscribe();
});
source.subscribe(refCounter);
if (!refCounter.closed) {
connection = source.connect();
}
});
}
//# sourceMappingURL=refCount.js.map