edgeport - v1.0.3
    Preparing search index...

    Function retry

    • Runs fn, retrying it with exponential backoff while it throws a retryable error.

      The delay before retry n (0-based) is min(maxMs, baseMs * 2 ** n), optionally with full jitter. A non-retryable error (per RetryOptions.retryable) is rethrown immediately, as is the last error once attempts is exhausted.

      Type Parameters

      • T

        The resolved value of fn.

      Parameters

      • fn: () => Promise<T>

        The operation to run; typically a connect or a one-shot request.

      • opts: RetryOptions = {}

        Attempt count, backoff timing, jitter, and the retryable predicate.

      Returns Promise<T>

      Whatever fn resolves to.

      The last error fn threw, once attempts are exhausted or the error is not retryable.

      1.0.3

      import { retry } from 'edgeport/util';
      import { connect } from 'edgeport/ssh';

      // retry the connect up to 4 times on transient network errors; a bad password fails at once
      const ssh = await retry(() => connect({ hostname: 'box', username: 'u', password: pw }), {
      attempts: 4
      });