npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

promising-utils

v0.2.2

Published

A utility library for promises, support both esm and commonjs

Downloads

20,585

Readme

promising-utils

A utility library for promise, supports both commonjs and ESM

npm install promising-utils --save
yarn add promising-utils

wait

Used when try to wait/sleep/delay for some time options

- duration: number
// miliseconds

timeout

- duration?: number
// milliseconds
- timeoutMsg?: string
// custom error message returns from reject

if duration is not defined, then it will never time out

retry

Used to retry a promise if rejected

- retries?: number
// Number of retry times

- timeout?: number
 // define timeout for each promsie

- retryIf?: (err: any, retriedTimes: number) => boolean;
// only retry when this return true

- retryUntil?: (err: any, count: number) => boolean;
// stop retry when this return true

-  delay?: number | ((count: number) => number);
// A number or function that returns how long it should wait before next retry. `count` is the number of times it's been retried

if 2 or more of retries, retryIf and retryUntil are defined at same time, retry will stop when first condition is met.

series

Used when to run a promise one at a one in sequence.

delay?: number | ((count: number) => number);
// delay between each promise execution
onEachStart?: (index: number) => void;
// called when each promise is executed
onEachEnd?: (index: number) => void;
// calle when each promise is resolved
stopOnReject?: boolean;
// If a promise is rejected, then stop the flow
waterFall?: boolean;
// If waterFall is true, then the current promise will receive resolved result from last promise as input

series is basically batch with size is 1

batch

Similar to series, but can run a batch of promises at one time, 2nd batch won't start until all promises in first batches finish

size?: number;
delay?: number | ((count: number) => number);
onBatchStart?: (index: number) => void;
onBatchEnd?: (index: number) => void;
stopOnReject?: boolean;
waterFall?: boolean;
waterFallInitialValue?: any;

parallel

Used when want to have fixed number of concurrent promises run at any time.

concurrency?: number;
// Number of concurrent promises running
timeout?: number;
// timeout for each promise
retries?: number;
// default is 0
stopOnReject?: boolean;

The difference between parallel and batch:

Assume we have 30 promises to run

if use parallel with concurrency to be 10. Then first 10 promises start to run, if 1 promise finished, the 11th promise will fill in to maintain total concurrency number as 10. and so on so forth.

if use batch, the first 10 promises start to run, if 1 promise finish, nothing happens, it continue to wait for rest 9 promises to finish, only after all 10 promises finish, the next batch of 10 will start to run.