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

ploop

v3.1.2

Published

Promise LOOPing utility functions

Downloads

13

Readme

ploop

Promise LOOPing utility functions.

Examples

...

Looping functions

/**
 * Retry
 * 
 * `opts` has to be a number or an options object with fields:
 * - {number}           limit       - maximum number of retries
 * - {number:function}  backoff     - backoff function or number of milliseconds to pause after each 
 * - {function}         before      - function called before every attempt (can be asynchronous)
 * - {function}         after       - function called after every attempt (can be asynchronous)
 *
 * @param {number|object} opts  maximum number of retries or options object
 * @param {function} action     an action to retry (can be asynchronous)
 * @param {any} [initialResult]
 * @returns {Promise}
 */
function retry(opts, action, initialResult)
/**
 * Map concurrently
 * 
 * @param {array} collection
 * @param {function} mapper 
 * @param {boolean} [breakEarly = false]
 * @param {number} [concurrency = Infinite]
 */
function map(collection, mapper, breakEarly = false, concurrency = 1234567890)
/**
 * Map serially
 * 
 * @param {array} collection 
 * @param {function} mapper 
 * @param {boolean} [breakEarly = false] 
 */
function map(collection, mapper, breakEarly = false, concurrency = 1)
/**
 * While - Do loop
 * 
 * @param {function|falsy} before   called before every action call
 * @param {function} action         iterated action
 * @param {any} initialResult
 */
function whileDo(before, action, initialResult)
/**
 * Do - While loop
 * 
 * @param {function} [after]        called after every action call
 * @param {function} action         iterated action
 * @param {any} initialResult
 */
function doWhile(after, action, initialResult)
/**
 * Generic looping utility, used internally by more specialised functions.
 * 
 * `before` and `after` functions are used as loop stopping conditions.
 *
 * @param {function|falsy} before   called before every action call
 * @param {function} action         iterated action
 * @param {function} [after]        called after every action call
 * @param {any} [initialResult]     value used in the first iteration
 * @param {number} [counter = 1]    interation number
 * @returns {Promise}
 */
function loop(before, action, after, initialResult, counter = 1)

Utility functions

/**
 * Creates a function that returns a promise resolved after <i>milllis</i> milliseconds.
 *
 * Simple usage:
 * <pre>  delayResolve(100)('!').then(shout => console.log('delayed message' + shout))</pre>
 *
 * Chained usage with argument forwarding:
 * <pre>
 *   Promise.resolve(333)
 *       .then(delayResolve(100))
 *       .then(res => console.log('111 + 222 =', res))</pre>
 *
 * @param {number} millis   number of milliseconds to wait
 * @returns {function(value): Promise}
 */
function delayResolve(millis)
/**
 * Similar to delayResolve, but created function rejects instead.
 * 
 * Chained usage with argument forwarding:
 * <pre>
 *   Promise.reject(333)
 *       .catch(delayReject(100))
 *       .catch(res => console.log('111 + 222 =', res))</pre>
 * 
 * @param {number} millis   number of milliseconds to wait
 * @returns {function(value): Promise}
 */
function delayReject(millis)
/**
 * 
 * @param {number} millis   number of milliseconds to wait
 * @param {any} [value]     value to resolve after `millis` milliseconds
 * @returns {Promise}
 */
function delay(millis, value)