相关疑难解决方法(0)

为什么我会在gulp中获得"多次调用任务完成回调"?

鉴于以下gulp任务,为什么我会收到以下错误?

错误:任务完成回调调用次数过多

function myTask(options, cb) { // cb is the gulp cb
  var serverInstance = http.createServer(dispatch({ /*routes*/ }));

  serverInstance.listen(options.port, function() {
    cb(); // Stack trace identifies this line as throwing the error
  });
}

function partial(fn) {   
    var args = Array.prototype.slice.call(arguments, 1);

    return function() {
        return fn.apply(this, args.concat(Array.prototype.slice.call(arguments)));
    };
}

gulp.task('task-name', ['task-dependency'], partial(myTask, { port: 8080 }));
Run Code Online (Sandbox Code Playgroud)

编辑:

以下修改使其工作(但我的问题仍然存在):

gulp.task('task-name', ['task-dependency'], function(cb) {
  partial(myTask, { port: 8080 })(cb);
});
Run Code Online (Sandbox Code Playgroud)

javascript gulp

9
推荐指数
1
解决办法
3676
查看次数

标签 统计

gulp ×1

javascript ×1