/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Diagnostic, ObservableValue } from "#general";
class NodeActivity {
  #actors = /* @__PURE__ */ new Set();
  #inactive = ObservableValue(true);
  get inactive() {
    return this.#inactive;
  }
  get actors() {
    return [...this.#actors.values()];
  }
  begin(description, onClose) {
    const elapsed = Diagnostic.elapsed();
    const actor = {
      stack: [description],
      get elapsed() {
        return elapsed;
      },
      get [Diagnostic.value]() {
        const result = Array();
        for (const frame of this.stack) {
          if (result.length) {
            result.push("\u25B8");
          }
          result.push(frame);
        }
        return result;
      },
      frame(description2) {
        this.stack.push(description2);
        return {
          [Symbol.dispose]: () => {
            this.stack.pop();
          }
        };
      },
      close: () => {
        onClose?.();
        this.#actors.delete(actor);
        if (!this.#actors.size) {
          this.#inactive.emit(true);
        }
      },
      [Symbol.dispose]: () => {
        actor.close();
      }
    };
    this.#actors.add(actor);
    if (this.#actors.size === 1) {
      this.#inactive.emit(false);
    }
    return actor;
  }
  get [Diagnostic.value]() {
    if (!this.#actors.size) {
      return Diagnostic.list([Diagnostic.weak("none")]);
    }
    return Diagnostic.list(this.actors);
  }
}
((NodeActivity2) => {
  NodeActivity2.activityKey = /* @__PURE__ */ Symbol("activity");
})(NodeActivity || (NodeActivity = {}));
export {
  NodeActivity
};
//# sourceMappingURL=NodeActivity.js.map
