a zip code crypto-currency system good for red ONLY

refCount.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /** PURE_IMPORTS_START .._Subscriber PURE_IMPORTS_END */
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b)
  4. if (b.hasOwnProperty(p))
  5. d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. import { Subscriber } from '../Subscriber';
  10. export function refCount() {
  11. return function refCountOperatorFunction(source) {
  12. return source.lift(new RefCountOperator(source));
  13. };
  14. }
  15. var RefCountOperator = /*@__PURE__*/ (/*@__PURE__*/ function () {
  16. function RefCountOperator(connectable) {
  17. this.connectable = connectable;
  18. }
  19. RefCountOperator.prototype.call = function (subscriber, source) {
  20. var connectable = this.connectable;
  21. connectable._refCount++;
  22. var refCounter = new RefCountSubscriber(subscriber, connectable);
  23. var subscription = source.subscribe(refCounter);
  24. if (!refCounter.closed) {
  25. refCounter.connection = connectable.connect();
  26. }
  27. return subscription;
  28. };
  29. return RefCountOperator;
  30. }());
  31. var RefCountSubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  32. __extends(RefCountSubscriber, _super);
  33. function RefCountSubscriber(destination, connectable) {
  34. _super.call(this, destination);
  35. this.connectable = connectable;
  36. }
  37. /** @deprecated internal use only */ RefCountSubscriber.prototype._unsubscribe = function () {
  38. var connectable = this.connectable;
  39. if (!connectable) {
  40. this.connection = null;
  41. return;
  42. }
  43. this.connectable = null;
  44. var refCount = connectable._refCount;
  45. if (refCount <= 0) {
  46. this.connection = null;
  47. return;
  48. }
  49. connectable._refCount = refCount - 1;
  50. if (refCount > 1) {
  51. this.connection = null;
  52. return;
  53. }
  54. ///
  55. // Compare the local RefCountSubscriber's connection Subscription to the
  56. // connection Subscription on the shared ConnectableObservable. In cases
  57. // where the ConnectableObservable source synchronously emits values, and
  58. // the RefCountSubscriber's downstream Observers synchronously unsubscribe,
  59. // execution continues to here before the RefCountOperator has a chance to
  60. // supply the RefCountSubscriber with the shared connection Subscription.
  61. // For example:
  62. // ```
  63. // Observable.range(0, 10)
  64. // .publish()
  65. // .refCount()
  66. // .take(5)
  67. // .subscribe();
  68. // ```
  69. // In order to account for this case, RefCountSubscriber should only dispose
  70. // the ConnectableObservable's shared connection Subscription if the
  71. // connection Subscription exists, *and* either:
  72. // a. RefCountSubscriber doesn't have a reference to the shared connection
  73. // Subscription yet, or,
  74. // b. RefCountSubscriber's connection Subscription reference is identical
  75. // to the shared connection Subscription
  76. ///
  77. var connection = this.connection;
  78. var sharedConnection = connectable._connection;
  79. this.connection = null;
  80. if (sharedConnection && (!connection || sharedConnection === connection)) {
  81. sharedConnection.unsubscribe();
  82. }
  83. };
  84. return RefCountSubscriber;
  85. }(Subscriber));
  86. //# sourceMappingURL=refCount.js.map