Options
All
  • Public
  • Public/Protected
  • All
Menu

@mhio/pinky

Index

Type aliases

BoolOrPromiseBoolFunction: () => boolean | Promise<boolean>

Type declaration

    • (): boolean | Promise<boolean>
    • Returns boolean | Promise<boolean>

MapperFunction: (element: any, index?: any) => any

Type declaration

    • (element: any, index?: any): any
    • Parameters

      • element: any
      • Optional index: any

      Returns any

Functions

  • allProps(obj: {}): Promise<{}>
  • Resolve all promises in an object

    Parameters

    • obj: {}

      The object to resolve properties of

      • [key: string]: Promise<any>

    Returns Promise<{}>

    obj - New object of resolved promise properties

  • delay(ms: number): Promise<void>
  • delay for ms

    Parameters

    • ms: number

      The milliseconds to delay for

    Returns Promise<void>

  • delayFrom(ts: number, ms: number): Promise<void>
  • Delay from a timestamp for milliseconds

    Parameters

    • ts: number

      The millisecond Date timestamp to start the delay from

    • ms: number

      The milliseconds to delay for

    Returns Promise<void>

  • delayTo(ts: number): Promise<void>
  • Delay until a timestamp milliseconds

    Parameters

    • ts: number

      The millisecond Date timestamp to start the delay from

    Returns Promise<void>

  • firstInSeriesWithoutError(iterable: Iterable<Promise<any>>): Promise<any>
  • Run a bunch of promises in series, if the one fails move onto the next.

    Parameters

    • iterable: Iterable<Promise<any>>

      The iterable

    Returns Promise<any>

    { description_of_the_return_value }

  • firstWithoutError(iterable: Iterable<Promise<any>>): Promise<any>
  • Run a bunch of promises, if the first fails return the next until all promises have been checked. All promises start resolving immediately.

    Parameters

    • iterable: Iterable<Promise<any>>

      The iterable

    Returns Promise<any>

    { description_of_the_return_value }

  • map an async function across an iterable

    Parameters

    Returns Promise<any[]>

    Array of resolved promises

  • mapConcurrent(iterator_in: Iterable<any>, asyncFn: MapperFunction, worker_count: number): Promise<any[]>
  • map an async function across an iterable with up to N promises

    Parameters

    • iterator_in: Iterable<any>
    • asyncFn: MapperFunction

      The asynchronous function

    • worker_count: number

    Returns Promise<any[]>

    • Array of all resolved values
  • mapSeries(iterable: Iterable<any>, asyncFn: MapperFunction): Promise<any[]>
  • map an async function in series across an iterable

    Parameters

    • iterable: Iterable<any>
    • asyncFn: MapperFunction

      The asynchronous function

    Returns Promise<any[]>

    • Array of all resolved values
  • noop(): void
  • outerSettle(): (undefined | Promise<unknown>)[]
  • Create a promise and return the promise, resolve and reject Allows you to choose whether to resolve/reject something outside the promise scope

    Returns (undefined | Promise<unknown>)[]

    • [ promise, resolve, reject ]
  • waitFor(timeout_ms: number, condition_fn: BoolOrPromiseBoolFunction, options?: { label: undefined | string; wait_ms: undefined | number }): Promise<{ count: number; result: true; total_ms: number }>
  • Wait until a timestamp or some condition function to become truthey. Can be an async or standard function

    throws

    {Error}

    Parameters

    • timeout_ms: number

      The Date timestamp to wait until

    • condition_fn: BoolOrPromiseBoolFunction

      The test function to call repeatedly

    • options: { label: undefined | string; wait_ms: undefined | number } = {}

      Options

      • label: undefined | string

        Label to attach to thrown Error

      • wait_ms: undefined | number

        Wait between tests (1000)

    Returns Promise<{ count: number; result: true; total_ms: number }>

  • workerAll(number_of_workers: number, iterator_in: Iterable<any>, asyncFn: MapperFunction): Promise<any[]>
  • Use n workers to resolve a function across an iterable. (via .mapSeries) Results array is grouped by worker, then the order a worker iterated in, so doesn't match the initial array order. if you need to inspect results include some type of id in the return. mapConcurrent should replace this

    Parameters

    • number_of_workers: number

      Number of functions to execute

    • iterator_in: Iterable<any>

      The iterator of values to use

    • asyncFn: MapperFunction

      The async function

    Returns Promise<any[]>

    • Unordered array of resolved values

Generated using TypeDoc