export async function repeat()

in fuse-ui-shared/decorators/retry.ts [133:159]


export async function repeat<T>(action: () => Promise<T>, canRetry: (v: any) => Promise<boolean>, wait: () => Promise<void>): Promise<T> {
  const result = createDeferred<T>();

  const inner = async () => {
    try {
      const x = await action();
      result.resolve(x);
    } catch (innerError) {
      if (await canRetry(innerError)) {
        try {
          await wait();
          //tslint:disable-next-line:no-floating-promises
          inner();
        } catch (waitError) {
          result.reject(waitError);
        }
      } else {
        result.reject(innerError);
      }
    }
  };

  //tslint:disable-next-line:no-floating-promises
  inner();

  return result.promise;
}