3.1.2 • Published 6 years ago

ploop v3.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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)
3.1.2

6 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.0.2

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago