Created
August 26, 2013 09:59
-
-
Save AmarPrabhu/6339909 to your computer and use it in GitHub Desktop.
iterate over a collection, perform an asynchronous task for each item, but only let x tasks run at the same time, and when they're all done do something else. From: http://www.sebastianseilund.com/nodejs-async-in-practice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.delete('/messages/:messageIds', function(req, res, next) { | |
var messageIds = req.params.messageIds.split(','); | |
async.forEachLimit(messageIds, 5, function(messageId, callback) { | |
db.delete('messages', messageId, callback); | |
}, function(err) { | |
if (err) return next(err); | |
res.json({ | |
success: true, | |
message: messageIds.length+' message(s) was deleted.' | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment