Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "promise/try-one-by-one"

Index

Functions

Functions

tryOneByOne

  • tryOneByOne<T>(promises: Array<Promise<T> | function>): Promise<T>
  • Tries a set of promises one by one with given order. Breaks the call when a promise resolved. Otherwise keeps trying incoming promises until the list is finished.


    Example:

    import { tryOneByOne } from "@thalesrc/js-utils/promise";
    
    async function fooFunction() {
      const foo = await tryOneByOne([
        () => someCall(),
        (err) => anotherCall(),
        (err) => fooPromise()
      ]);
    
      // do stuff
    }
    

    Static Example:

    import "@thalesrc/js-utils/promise/static/try-one-by-one";
    
    async function fooFunction() {
      const foo = await Promise.tryOneByOne([
        () => someCall(),
        (err) => anotherCall(),
        (err) => fooPromise()
      ]);
    
      // do stuff
    }
    

    Type parameters

    • T

    Parameters

    • promises: Array<Promise<T> | function>

      List of promises to try one by one with the order

    Returns Promise<T>

Generated using TypeDoc