import { createAbortable as n } from "../abortable/main.js";
import { createDeferred as c } from "../deferred/main.js";
import { tryResolve as l } from "../../../utils/async/main.js";
import { enumerable as a, getter as p } from "../../../utils/struct/property.js";
import { isUndefined as b } from "../../../utils/value/is.js";
const _ = (f) => {
  const i = n(), e = c();
  let r;
  return Object.defineProperties(function(...m) {
    b(r) ? e.refresh() : i.abort();
    const o = l.call(this, f, i.refresh().signal, ...m);
    return (async () => {
      let t = r === (r = o);
      try {
        const s = await o.finally(() => {
          t = r === o, t && (r = void 0);
        });
        t && e.resolve(s);
      } catch (s) {
        t && e.reject(s);
      }
    })(), o;
  }, {
    abort: a(i.abort),
    promise: p(() => e.promise),
    refresh: a(() => {
      e.refresh();
    })
  });
};
export {
  _ as createPromisor
};
