import { EventEmitter } from "eventemitter3";
import { Subscription } from "../../types/subscription.js";
class Notifier {
  #eventEmitter = new EventEmitter();
  #lastStateReceived;
  #newSubscription() {
    const notify = (state) => subscription.push(state);
    const subscription = Subscription.create({
      coalesce: (curr) => curr,
      cleanup: () => this.#eventEmitter.off("version", notify)
    });
    return { notify, subscription };
  }
  subscribe() {
    const { notify, subscription } = this.#newSubscription();
    this.#eventEmitter.on("version", notify);
    if (this.#lastStateReceived) {
      notify(this.#lastStateReceived);
    }
    return subscription;
  }
  notifySubscribers(state = { state: "version-ready" }) {
    this.#lastStateReceived = state;
    return this.#eventEmitter.listeners("version").map((notify) => notify(state)).map((pending) => pending.result);
  }
}
export {
  Notifier
};
//# sourceMappingURL=notifier.js.map
