node.js中有一个出色的流控制模块,称为asyncblock。如果适合您的情况将代码包装在函数中,则可以考虑以下示例:var asyncblock = require('asyncblock');var exec = require('child_process').exec;asyncblock(function (flow) { exec('node -v', flow.add()); result = flow.wait(); console.log(result); // There'll be trailing \n in the output // Some other jobs console.log('More results like if it were sync...');});