refCount.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.refCount = void 0;
  4. var lift_1 = require("../util/lift");
  5. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  6. function refCount() {
  7. return lift_1.operate(function (source, subscriber) {
  8. var connection = null;
  9. source._refCount++;
  10. var refCounter = OperatorSubscriber_1.createOperatorSubscriber(subscriber, undefined, undefined, undefined, function () {
  11. if (!source || source._refCount <= 0 || 0 < --source._refCount) {
  12. connection = null;
  13. return;
  14. }
  15. var sharedConnection = source._connection;
  16. var conn = connection;
  17. connection = null;
  18. if (sharedConnection && (!conn || sharedConnection === conn)) {
  19. sharedConnection.unsubscribe();
  20. }
  21. subscriber.unsubscribe();
  22. });
  23. source.subscribe(refCounter);
  24. if (!refCounter.closed) {
  25. connection = source.connect();
  26. }
  27. });
  28. }
  29. exports.refCount = refCount;
  30. //# sourceMappingURL=refCount.js.map