import { createDeferred as c } from "../../../../primitives/async/deferred/main.js";
import { isWatchlistUnsubscribeToken as l } from "../../../../primitives/reactive/watchlist/main.js";
import { boolOrTrue as a } from "../../../../utils/value/bool.js";
const m = async (e) => {
  const r = c(), t = r.promise, n = e.context.refreshing;
  let o, i, s = e.subscribe((f) => {
    if (l(f)) {
      r.resolve();
      return;
    }
    if (o ??= e.context.refreshing, !e.context.refreshing) {
      if (a(e.context.isExpired) && (i ??= !(n || o))) {
        i = !1, e.refresh();
        return;
      }
      r.resolve();
    }
  });
  return t.finally(() => {
    s(), s = null;
  }), t;
};
export {
  m as default
};
