gulp没有调用回调-它只是在任务结束时挂起

cho*_*ovy 2 node.js gulp

callback 正在射击,但任务挂起 Finished 'hooks:pull' after 2.04 s

gulp.task('hooks:pull', function(callback){
  var files = [
    { remote: '~/deploy/test.example.com/hooks/post-receive', local: './bin/post-receive.test' },
    { remote: '~/deploy/staging.example.com/hooks/post-receive', local: './bin/post-receive.staging' },
    { remote: '~/deploy/example.com/hooks/post-receive', local: './bin/post-receive.production' }
  ];

  async.each(files, function(file, cb) {
    var opts = {
      host: 'example.com'
    };

    opts.file = file.remote;
    opts.path = file.local;

    scp.get(opts, function(err) {
      if (err) {
        console.error(err);
        return cb(err);
      }

      console.log('%s hook has been pulled!', file.local);
      cb();
    });
  }, function(err){
    if ( err ) {
      console.error(err);
      return callback(err);
    }

    callback();
  });
});
Run Code Online (Sandbox Code Playgroud)

如何获取调用回调并退出/返回的信息?

刚跑步 gulp hooks:pull

Mat*_*chs 5

如果节点挂起而不是退出,则可能是任务仍在运行。

您可以使用Gulp stop挂钩将其杀死,或者如果您不在乎(并且在您的任务中不启动任何异步清理功能),也可以退出整个流程。

应该这样做:

process = require("process");
gulp.on('stop', function() { process.exit(0); }
Run Code Online (Sandbox Code Playgroud)

  • *叹*。此解决方案确实有效。是的,这是一个快速而肮脏的黑客,这就是它原本打算做的一切。请不要在不解释原因的情况下投票。 (2认同)