// @ts-nocheck
export function withResolvers<T, R = any>(): {
  promise: Promise<T>;
  resolve: (value: T | PromiseLike<T>) => void;
  reject: (reason?: R) => void
} {
  if ( typeof Promise[ 'withResolvers' ] === 'function' ) {
    withResolvers = () => Promise.withResolvers();
    return Promise.withResolvers();
  } else {
    const fn = () => {
      let resolve, reject;
      const promise = new Promise<T>((res, rej) => {
        resolve = res;
        reject = rej;
      });
      return { promise, resolve, reject };
    };
    withResolvers = fn;
    return fn();
  }
}
