promise-count

0.0.7 • Public • Published

promise-count

Come in handy a few times; an alternative to Promise.all but without the fail-fast behaviour

const promise1 = new Promise((resolve, reject) => setTimeout(() => reject(1), 5000))
const promise2 = new Promise((resolve, reject) => resolve(2))
promises = [promise1, promise2, promise2]
// calling PromiseCount(promises) would resolve to 
[{success: true, value: 2}, {success: true, value: 2}, { success: false, value: 1}]

Example usage

async () => {
  const promises = [promise1, promise2, promise2]

  const results = await PromiseCount(promises)

  console.log('Number of resolved promises:', results.filter(r => r.success).length)
  console.log('Number of rejected promises:', results.filter(r => !r.success).length)
}

Readme

Keywords

none

Package Sidebar

Install

npm i promise-count

Weekly Downloads

1

Version

0.0.7

License

ISC

Unpacked Size

3.05 kB

Total Files

3

Last publish

Collaborators

  • cpv123