New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

asyncforeach

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asyncforeach

Lightweight async Array-forEach-method.

  • 1.0.0-beta.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
decreased by-79.49%
Maintainers
2
Weekly downloads
 
Created
Source

asyncforeach Build Status Coverage Status

Lightweight async Array-forEach-method.

Description

In a microservice world, you want to fire requests in parallel and act on all of their returns. This can be done very barebones with this tiny module.

For better support and lifetime handling, as well as a better API go to Steed.

Example

const arr = []

arr.push(function one (task, index, array, cb) {
  process.nextTick(() => {
    return cb(null, {'one': 'one'})
  })
})

arr.push(function two (task, index, array, cb) {
  console.log('calling two')
  setTimeout(function () {
    return cb(null, {'two': 'two'})
  }, 1000)
})


asyncForEach(arr, (err, res) => {
  console.log(err) // null
  console.log(res) // [ {'one': 'one'}, {'two': 'two'} ]
                   // order is guaranteed
})

or with an error:

const arr = []

arr.push(function one (task, index, array, cb) {
  process.nextTick(() => {
    return cb(new Error('Simple Error'), {'one': 'one'})
  })
})

arr.push(function two (task, index, array, cb) {
  console.log('calling two')
  setTimeout(function () {
    return cb(new Error(), {'two': 'two'})
  }, 1000)
})


asyncForEach(arr, (err, res) => {
  console.log(err) // err instanceof Error -> true
  console.log(res) // undefined
})

Prior Art

countless

  • aysnc
  • Promise

(WIP)

License

MIT

Keywords

FAQs

Package last updated on 07 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc