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

标签 node.js gulp

回调 正在触发,但任务只是卡在 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();
  });
});

如何让它调用回调并退出/返回?

只需运行 gulp hooks:pull

最佳答案

如果 Node 挂起而不是退出,大概是任务仍在运行。

你可以使用 Gulp stop 钩子(Hook)来杀死它,或者如果你不在乎的话就退出整个事情(如果你没有在你的任务中启动任何异步清理功能) .

应该这样做:

process = require("process");
gulp.on('stop', function() { process.exit(0); }

关于node.js - gulp 没有调用回调——它只是在任务结束时挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26708608/

相关文章:

node.js - 在 TypeScript 中使用原生 JS 方法/调用的正确方法是什么

npm - NPM错误安装Gulp : Error: ENOENT, lstat

gulp-changed/gulp-newer + gulp-rename 不起作用

javascript - 使用 Critical 和 Gulp 为每个 *.HTML 文件生成 Critical CSS

node.js - 巴别塔错误 : "Error: Cannot find module ' babel-plugin-transform-object-rest-spread' from '/vagrant' "

node.js - 在 Express 3.x 中加载样式表时出错

node.js - 在adonis js中强制过期jwt token

javascript - jshint - 不要在循环内创建函数 - 谷歌地图

jquery - 由于生成器 ko 的 jQuery 错误,Gulp 失败了默认任务

node.js - SailsJS 中的 HTTP 请求缓存?