@reverecre/promise
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

@reverecre/promise

Installation

npm i @reverecre/promise

🧰 Functions

⚙️ chunkArray

Splits an array into subarray chunks.

Function Type
chunkArray <T>(arr: readonly T[], chunkSize: number) => T[][]

Parameters:

  • arr: The array to be chunked.
  • chunkSize: Size of the sub-arrays.

⚙️ workerPool

Processes an array of items using a given callback and concurrency. Best used as an alternative to Promise.all(items.map(...)) as it limits concurrency.

Function Type
workerPool <In, Out>(tasks: readonly In[], fn: (task: In) => MaybePromise<Out>, workers?: number) => Promise<readonly Out[]>

Parameters:

  • tasks: Items to be processed.
  • fn: Callback to map each item.
  • workers: Maximum number of promises to execute at once.

⚙️ chunkedWorkerPool

workerPool implementation that batches tasks into chunks before calling fn to allow for processing in small batches.

Function Type
chunkedWorkerPool <In, Out>(tasks: readonly In[], fn: (task: In[]) => MaybePromise<Out[]>, { chunkSize, workers }?: { workers?: number; chunkSize?: number; }) => Promise<readonly Out[]>

Parameters:

  • tasks: Items to be processed.
  • fn: Callback to map each item.
  • options: Concurrency controls.

⚙️ sleep

Waits a given number of milliseconds.

Function Type
sleep (ms: number) => Promise<unknown>

⚙️ retry

Wraps a function that returns a promise adding retry logic, before throwing the last seen error.

Function Type
retry <In extends unknown[], Out>(fn: (...args: In) => Promise<Out>, { attempts, backoffDuration, backoffJitter, onError, }?: RetryOptions) => (...args: In) => Promise<Out>

⚙️ retryWithDefault

Wraps a function that returns a promise adding retry logic, before throwing returning a default.

Function Type
retryWithDefault <In extends unknown[], Out>(fn: (...args: In) => Promise<Out>, defaultTo: Out, opts?: RetryOptions) => (...args: In) => Promise<Out>

Readme

Keywords

Package Sidebar

Install

npm i @reverecre/promise

Weekly Downloads

17

Version

0.1.0

License

MIT

Unpacked Size

14 kB

Total Files

6

Last publish

Collaborators

  • rv_reverecre
  • ederski
  • rrdelaney