A function for looping over items with asynchronous callbacks synchronously (for node.js)