// @bun
var __require = import.meta.require;

// .angular-partial-tmp/src/core/streamingSlotRegistrar.ts
var STREAMING_SLOT_REGISTRAR_KEY = Symbol.for("absolutejs.streamingSlotRegistrar");
var getRegistrarGlobal = () => globalThis;
var setStreamingSlotRegistrar = (nextRegistrar) => {
  getRegistrarGlobal()[STREAMING_SLOT_REGISTRAR_KEY] = nextRegistrar;
};
var registerStreamingSlot = (slot) => {
  getRegistrarGlobal()[STREAMING_SLOT_REGISTRAR_KEY]?.(slot);
};

// .angular-partial-tmp/src/core/streamingSlotRegistry.ts
var STREAMING_SLOT_STORAGE_KEY = Symbol.for("absolutejs.streamingSlotAsyncLocalStorage");
var getStorageGlobal = () => globalThis;
var isServerRuntime = () => typeof process !== "undefined" && typeof process.versions?.node === "string";
var ensureAsyncLocalStorage = async () => {
  const storageGlobal = getStorageGlobal();
  if (typeof storageGlobal[STREAMING_SLOT_STORAGE_KEY] !== "undefined") {
    return storageGlobal[STREAMING_SLOT_STORAGE_KEY];
  }
  if (!isServerRuntime()) {
    storageGlobal[STREAMING_SLOT_STORAGE_KEY] = null;
    return storageGlobal[STREAMING_SLOT_STORAGE_KEY];
  }
  const mod = await import("async_hooks");
  storageGlobal[STREAMING_SLOT_STORAGE_KEY] = new mod.AsyncLocalStorage;
  return storageGlobal[STREAMING_SLOT_STORAGE_KEY];
};
var registerStreamingSlot2 = (slot) => {
  const storage = getStorageGlobal()[STREAMING_SLOT_STORAGE_KEY];
  if (!storage)
    return;
  const store = storage.getStore();
  if (!store)
    return;
  store.set(slot.id, slot);
};
setStreamingSlotRegistrar(registerStreamingSlot2);
var runWithStreamingSlotRegistry = async (task) => {
  const storage = await ensureAsyncLocalStorage();
  if (!storage) {
    return {
      result: await task(),
      slots: []
    };
  }
  return storage.run(new Map, async () => {
    const result = await task();
    const store = storage.getStore();
    return {
      result,
      slots: store ? [...store.values()] : []
    };
  });
};
export {
  runWithStreamingSlotRegistry
};
