Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@reverecre/promise

Package Overview
Dependencies
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reverecre/promise

A utility library for working with promises

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

@reverecre/promise

Installation

npm i @reverecre/promise

:toolbox: Functions

  • chunkArray
  • workerPool
  • chunkedWorkerPool
  • sleep
  • retry
  • retryWithDefault

:gear: chunkArray

Splits an array into subarray chunks.

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

Parameters:

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

:gear: 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.

FunctionType
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.

:gear: chunkedWorkerPool

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

FunctionType
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.

:gear: sleep

Waits a given number of milliseconds.

FunctionType
sleep(ms: number) => Promise<unknown>

:gear: retry

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

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

:gear: retryWithDefault

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

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

Keywords

FAQs

Package last updated on 16 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc