Skip to content

idle listeners on CountingGovernors #16

@michaelficarra

Description

@michaelficarra

CountingGovernors should have idle listeners. addIdleListener registers a callback and removeIdleListener unregisters it.

  addIdleListener(cb: () => void) {
    this.#idleListeners.push(cb);
  }

  removeIdleListener(cb: () => void) {
    const idx = this.#idleListeners.indexOf(cb);
    if (idx >= 0) {
      this.#idleListeners.splice(idx, 1);
    }
  }

  #notifyIdleListeners() {
    for (const cb of this.#idleListeners) {
      try {
        cb();
      } catch {}
    }
  }

Whenever a token is disposed and there are no more active tokens, all of the currently registered callbacks should be called.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions