所以考虑到我有一个这样的播种机:
var seedDatabase = function () {
var promises = [];
promises.push(createProductTypes());
promises.push(createCompensationTypes());
promises.push(createDataSources());
promises.push(createPeriodsAndStages());
promises.push(createExportDestinations());
return Promise.all(promises);
};
function createCompensationTypes() {
return models.sequelize
.transaction(
{
isolationLevel: models.sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED
},
function (q) {
return models.CompensationType
.findAll()
.then(function (result) {
if (!result || result.length == 0) {
return models.CompensationType
.bulkCreate(compensationTypes, { transaction: q })
.then(function () {
console.log("CompensationTypes created");
})
}
else {
console.log("CompensationTypes seeder skipped, already objects in the database...");
return;
}
});
})
.then(function (result) {
console.log("CompensationTypes seeder finished...");
return;
})
.catch(function (error) {
console.log("CompensationTypes seeder exited with error: " + error.message);
return;
});
};
出于某种原因,这会挂起执行。然而,当我评论添加到阵列中的任何一个承诺时,一切都顺利进行。
此外,当我在seedDatabase
函数中执行以下操作时,它也有效:
var seedDatabase = function () {
var promises = [];
promises.push(createProductTypes());
promises.push(createDataSources());
promises.push(createPeriodsAndStages());
promises.push(createExportDestinations());
return Promise.all(promises).then(function() {
return createCompensationTypes()
});
};
这很奇怪,因为很明显我的代码正在运行,但仍然依赖于额外的承诺。因此我的问题是,使用sequelizeJS时是否存在最大的并发承诺或交易?或者我在这里忽略了其他什么?