
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A simple way to wait for multiple asynchronous calls to return in Node.js.
Just a little utility class I wrote for dealing with parallel code. It lets you spin off a bunch of asynchronous operations and wait for them to finish.
Waiter is similar to other projects like Step, async, and Seq, but with a focus on parallel operations that return values.
Read three files asynchronously.
var waiter = new Waiter
var aFile = waiter(),
bFile = waiter(),
cFile = waiter()
fs.readFile('a.txt', aFile)
fs.readFile('b.txt', bFile)
fs.readFile('c.txt', cFile)
// wait for them to finish
waiter.waitForAll(function(error) {
if (error) {
// inspect individual errors in aFile.error, bFile.error, and cFile.error
throw "oh no!"
}
// do something with aFile.value, bFile.value, and cFile.value
})
You can call waiter() as many times as you want --- but call them all before calling waitForAll!
var files = [ ... ]
var waiter = new Waiter
var filesContent = files.map(function(file) {
// Alternative syntax, pass a function into waiter(), and get the callback as an argument
return waiter(function(done) {
fs.readFile(file,done)
})
})
waiter.waitForAll(function(error) {
// do something with error or fileContents[x].value
}, 2000) // optional timeout parameter
Don't care about the values? You don't have to store the result of waiter():
var waiter = new Waiter
fs.writeFile('a.txt', 'hello a!', waiter())
fs.writeFile('b.txt', 'hello b!', waiter())
fs.writeFile('c.txt', 'hello c!', waiter())
waiter.waitForAll(function(error) {
if (error) {
console.error("Oh no!", error)
} else {
// all files have been written successfully!
}
})
Alternative syntax if you don't care about the values:
new Waiter(
function(done) {
fs.writeFile('a.txt', 'hello a!', done)
},
function(done) {
fs.writeFile('b.txt', 'hello b!', done)
}
).waitForAll(function(error) {
// same old...
})
Waiter is open source software under the zlib license.
FAQs
A simple way to wait for multiple asynchronous calls to return
We found that waiter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.