Javascript 如何使用许多同步Sequelize调用退出节点进程?

Javascript 如何使用许多同步Sequelize调用退出节点进程?,javascript,node.js,sequelize.js,Javascript,Node.js,Sequelize.js,我有一些代码如下所示 Post.findAll(){ .then(function (posts) { var i; for (i in posts) { Comment.findAll({where: {post_id: posts[i].id}}){ .then(function (comments) { // do some stuff. return; }); }

我有一些代码如下所示

Post.findAll(){
.then(function (posts) {
    var i;

    for (i in posts) {

        Comment.findAll({where: {post_id: posts[i].id}}){
        .then(function (comments) {
            // do some stuff.

            return;
        });
    }

    return;
});
它运行,但从不退出。注释调用可以全部同步运行。通常我会按顺序运行,因此会有一系列的回访。但在这种情况下,这并不重要。进程只是挂起,永远不会退出。这是一个cron任务,所以我需要它在所有呼叫都被触发后退出


有办法做到这一点吗?

我认为问题在于您没有调用Sequelize::close。因此,连接可能会保持打开状态,直到某个超时,因此进程不会终止

从lib/sequelize.js:

/**
 * Close all connections used by this sequelize instance, and free all references so the instance can be garbage collected.
 *
 * Normally this is done on process exit, so you only need to call this method if you are creating multiple instances, and want
 * to garbage collect some of them.
 */
Sequelize.prototype.close = function () {
  this.connectionManager.close();
};
我有一些测试证明了这一点:

tests/00 demo/run.sh-正确终止 tests/01 demo no close/run.sh-调用关闭已注释,挂起