ixfx
    Preparing search index...

    Function promiseWithResolvers

    • Creates a new Promise, returning the promise along with its resolve and reject functions.

      const { promise, resolve, reject } = promiseWithResolvers();

      setTimeout(() => {
      resolve();
      }, 1000);

      await promise;

      Promise would be passed somewhere that expects a promise, and you're free to call resolve or reject when needed.

      Type Parameters

      • T

      Returns {
          promise: Promise<T>;
          reject: (reason: any) => void;
          resolve: (value: T) => void;
      }