{"size": 2016, "ext": "js", "max_stars_repo_path": "node_modules/bower/node_modules/insight/node_modules/inquirer/node_modules/rx/src/core/disposables/refcountdisposable.js", "max_stars_repo_name": "andela-jejezie/peopleProject", "max_stars_repo_stars_event_min_datetime": "2015-01-01T00:08:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:28:19.000Z", "max_issues_repo_path": "node_modules/bower/node_modules/insight/node_modules/inquirer/node_modules/rx/src/core/disposables/refcountdisposable.js", "max_issues_repo_name": "andela-jejezie/peopleProject", "max_issues_repo_issues_event_min_datetime": "2015-01-01T18:53:34.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-17T22:50:56.000Z", "max_forks_repo_path": "node_modules/bower/node_modules/insight/node_modules/inquirer/node_modules/rx/src/core/disposables/refcountdisposable.js", "max_forks_repo_name": "andela-jejezie/peopleProject", "max_forks_repo_forks_event_min_datetime": "2015-01-01T00:21:21.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T09:58:32.000Z"}
{"max_stars_count": 19780, "max_issues_count": 958, "max_forks_count": 3104, "avg_line_length": 34.7586206897, "max_line_length": 149, "alphanum_fraction": 0.6676587302}
  /**
   * Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
   */
  var RefCountDisposable = Rx.RefCountDisposable = (function () {

    function InnerDisposable(disposable) {
      this.disposable = disposable;
      this.disposable.count++;
      this.isInnerDisposed = false;
    }

    InnerDisposable.prototype.dispose = function () {
      if (!this.disposable.isDisposed && !this.isInnerDisposed) {
        this.isInnerDisposed = true;
        this.disposable.count--;
        if (this.disposable.count === 0 && this.disposable.isPrimaryDisposed) {
          this.disposable.isDisposed = true;
          this.disposable.underlyingDisposable.dispose();
        }
      }
    };

    /**
     * Initializes a new instance of the RefCountDisposable with the specified disposable.
     * @constructor
     * @param {Disposable} disposable Underlying disposable.
      */
    function RefCountDisposable(disposable) {
      this.underlyingDisposable = disposable;
      this.isDisposed = false;
      this.isPrimaryDisposed = false;
      this.count = 0;
    }

    /**
     * Disposes the underlying disposable only when all dependent disposables have been disposed
     */
    RefCountDisposable.prototype.dispose = function () {
      if (!this.isDisposed && !this.isPrimaryDisposed) {
        this.isPrimaryDisposed = true;
        if (this.count === 0) {
          this.isDisposed = true;
          this.underlyingDisposable.dispose();
        }
      }
    };

    /**
     * Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.
     * @returns {Disposable} A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime.
     */
    RefCountDisposable.prototype.getDisposable = function () {
      return this.isDisposed ? disposableEmpty : new InnerDisposable(this);
    };

    return RefCountDisposable;
  })();
