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
如果节点挂起而不是退出,则可能是任务仍在运行。
您可以使用Gulp stop挂钩将其杀死,或者如果您不在乎(并且在您的任务中不启动任何异步清理功能),也可以退出整个流程。
应该这样做:
process = require("process");
gulp.on('stop', function() { process.exit(0); }
Run Code Online (Sandbox Code Playgroud)