All Promise Utils functions from github.com/sindresorhus bundled together!
npm install p-fun --save
const p = require('p-fun')
/*
That's it!, now you can call any of his functions :)
*/
p.delay(1000)
.then(() => console.log('I waited 1000 milliseconds to send this message! :D'))
One important thing is that due to not all of the packages being legal variable names in JavaScript (for example the package p-map
would be interpreted as p - map
, like it would be a math equation)
Due to this, the keys in the object that represent the function will follow this naming convention:
- If the module does not start with
p-
, it will be temporary be added to the module name, like thisrequire('delay')
->require('p-delay')
p-
will now be removed from the key name, due to the recommended varible therequire('p-fun')
being assigned to isp
orP
, like the example above!- If the module name has hyphens (
-
) in it, it will get removed, and the following character will be capitalized, like thisrequire('do-whilst')
->require('doWhilst')
- Now the module name will get added to the object that this module is exporting, for example like this:
const p = { doWhilst: require('p-do-whilst') }
Returns an object with all the Promise util functions!
They will be mapped just like this:
all
->require('p-all')
: Run promise-returning & async functions concurrently with optional limited concurrencyany
->require('p-any')
: Wait for any promise to be fulfilledbreak
->require('p-break')
: Break out of a promise chaincancelable
->require('p-cancelable')
: Create a promise that can be canceledcatchIf
->require('p-catch-if')
: Conditional promise catch handlerdebounce
->require('p-debounce')
: Debounce promise-returning & async functionsdefer
->require('p-defer')
: Create a deferred promisedelay
->require('delay')
: Delay a promise a specified amount of timedoWhilst
->require('p-do-whilst')
: Calls a function repeatedly while a condition returns true and then resolves the promiseeachSeries
->require('p-each-series')
: Iterate over promises seriallyevent
->require('p-event')
: Promisify an event by waiting for it to be emittedevery
->require('p-every')
: Test whether all promises passes a testing functionfilter
->require('p-filter')
: Filter promises concurrentlyfinally
->require('p-finally')
:Promise#finally()
ponyfill - Invoked when the promise is settled regardless of outcomeforever
->require('p-forever')
: Run promise-returning & async functions repeatedly until you end ithardRejection
->require('hard-rejection')
: Make unhandled promise rejections fail hard right away instead of the default silent failif
->require('p-if')
: Conditional promise chainsimmediate
->require('p-immediate')
: Returns a promise resolved in the next event loop - thinksetImmediate()
isPromise
->require('p-is-promise')
: Check if something is a promiselazy
->require('p-lazy')
: Create a lazy promise that defers execution until.then()
or.catch()
is calledlimit
->require('p-limit')
: Run multiple promise-returning & async functions with limited concurrencylocate
->require('p-locate')
: Get the first fulfilled promise that satisfies the provided testing functionlog
->require('p-log')
: Log the value/error of a promiseloudRejection
->require('loud-rejection')
: Make unhandled promise rejections fail loudly instead of the default silent failmap
->require('p-map')
: Map over promises concurrentlymapSeries
->require('p-map-series')
: Map over promises seriallymemoize
->require('p-memoize')
: Memoize promise-returning & async functionsminDelay
->require('p-min-delay')
: Delay a promise a minimum amount of timeone
->require('p-one')
: Test whether some promise passes a testing functionpify
->require('pify')
: Promisify a callback-style functionpipe
->require('p-pipe')
: Compose promise-returning & async functions into a reusable pipelineprogress
->require('p-progress')
: Create a promise that reports progressprops
->require('p-props')
: LikePromise.all()
but forMap
andObject
queue
->require('p-queue')
: Promise queue with concurrency controlrace
->require('p-race')
: A betterPromise.race()
reduce
->require('p-reduce')
: Reduce a list of values using promises into a promise for a valuereflect
->require('p-reflect')
: Make a promise always fulfill with its actual fulfillment value or rejection reasonretry
->require('p-retry')
: Retry a promise-returning or async functionseries
->require('p-series')
: Run promise-returning & async functions in seriessettle
->require('p-settle')
: Settle promises concurrently and get their fulfillment value or rejection reasonsome
->require('p-some')
: Wait for a specified number of promises to be fulfilledtap
->require('p-tap')
: Tap into a promise chain without affecting its value or statethrottle
->require('p-throttle')
: Throttle promise-returning & async functionstime
->require('p-time')
: Measure the time a promise takes to resolvetimeout
->require('p-timeout')
: Timeout a promise after a specified amount of timetimes
->require('p-times')
: Run promise-returning & async functions a specific number of times concurrentlytry
->require('p-try')
:Promise#try()
ponyfill - Starts a promise chainwaitFor
->require('p-wait-for')
: Wait for a condition to be truewaterfall
->require('p-waterfall')
: Run promise-returning & async functions in series, each passing its result to the nextwhilst
->require('p-whilst')
: Calls a function repeatedly while a condition returns true and then resolves the promise
MIT