What you are doing is pretty idiomatic and wonderful, the only opportunity for improvement is to use the fact that Sequelize uses Bluebird for promises, so you get .map for free, which allows you to convert:
function createOrUpdateWidgets(widgetConfigObjects) { var promises = []; widgetConfigObjects.forEach(function(widgetConfig) { promises.push(createOrUpdateWidget(widgetConfig)); }); return Sequelize.Promise.all(promises); }
IN:
function createOrUpdateWidgets(widgetConfigObjects) { return Sequelize.Promise.map(widgetConfig, createOrUpdateWidget) }
Other than this minor improvement, you are tying promises correctly and seem to be using it correctly.
Benjamin gruenbaum
source share