// @ts-nocheck
export function withResolvers<T>(): {
  promise: Promise<T>;
  resolve: (value: T | PromiseLike<T>) => void;
  reject: (reason?: any) => void;
} {
  if ( typeof Promise.withResolvers === 'function' ) {
    withResolvers = Promise.withResolvers.bind(Promise);
    return Promise.withResolvers<T>();
  } else {
    const fn = function() {
      const out = {};
      out.promise = new Promise<T>((resolve_, reject_) => {
        out.resolve = resolve_;
        out.reject = reject_;
      });
      return out;
    };
    withResolvers = fn.bind(Promise);
    return fn();
  }
}
