gulp is not calling the callback — it just hangs at end of task

前提是你 提交于 2019-12-11 02:12:04

问题


callback is firing, but task just hangs on 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();
  });
});

How do I get it to call the callback and exit/return?

Just running gulp hooks:pull


回答1:


If node hangs instead of exiting, presumably a task is still running.

You can use the Gulp stop hook to kill it, or just to exit the whole thing if you don't care (and if you don't start any async cleanup functions in your tasks).

This should do it:

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



回答2:


I found my problem (PEBKAC)

I had this line at the top of the gulpfile.js which was causing it to hang.

var app = require('./server/index');

Not sure why I added that, but removing it fixed it.




回答3:


Works for me (?) with this setup:

var gulp = require('gulp');
var async = require('async');
var scp = require('scp');

gulp.task('default', function(callback) {
    var files = [
        { remote: '.gitconfig', local: './foo' },
        { remote: '.gitconfig', local: './bar' },
        { remote: '.gitconfig', local: './baz' }
    ];
    async.each(files, function(file, cb) {
        scp.get({ host: 'localhost', file: file.remote, path: file.local }, function(err) {
            if (err) {
                console.error(err);
                return cb(err);
            }
            console.log('%s has been pulled!', file.local);
            cb();
        });
    }, function(err) {
        if (err) {
            console.error(err);
            return callback(err);
        }
        callback();
    });
});

.. which is practically the same except host & files.



来源:https://stackoverflow.com/questions/26708608/gulp-is-not-calling-the-callback-it-just-hangs-at-end-of-task

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!