我如何强制大量呼叫同步运行? [英] How do I force gulp calls to run synchronously?
问题描述
我希望下面的呼叫电话一个接一个同步运行。但他们不遵循订单。
运行序列节点模块在这里没有帮助,因为我没有试图在系列中运行gulp任务(即它的语法类似于 gulp.task(mytask,[foo, (baz)]
等),而是在系列中咕噜咕噜打电话,如下所示。
gulp.task(dostuff,function(callback){
gulp
.src(...)
.pipe(gulp。 dest(...);
gulp
.src(...)
.pipe(gulp.dest(...);
gulp
.src(...)
.pipe(gulp.dest(...);
callback() ;
});
如何让它们一个接一个地运行?您可以使用 > async 作为呼叫的控制流,以便让他们只进行一项任务,同时避免您获得金字塔e所以像这样的东西应该对你的用例有好处:
var async = require('async');
gulp.task('yeah',function(cb){
async.series([
function(next){
gulp.src('.. '')
.pipe(gulp.dest('...')
.on('end',next);
},
function(next){
gulp.src('...')
.pipe(gulp.dest('...')
.on('end',next);
},
函数(下一个){
gulp.src('...')
.pipe(gulp.dest('...')
.on('end' ,下一个);
}
],cb);
});
这也可以让你有一些错误处理,并更好地发生问题的地方。
I want the gulp calls below to run synchronously, one after the other. But they do not follow an order.
The run-sequence node module doesn't help here, as I'm not trying to run gulp tasks in series (i.e. it has syntax similar to gulp.task("mytask", ["foo", "bar", "baz"]
etc.), but rather gulp "calls" in series, as you see below.
gulp.task("dostuff", function (callback) {
gulp
.src("...")
.pipe(gulp.dest("...");
gulp
.src("...")
.pipe(gulp.dest("...");
gulp
.src("...")
.pipe(gulp.dest("...");
callback();
});
How do I make them run one after the other?
You can use async as a control flow for your calls to get them in only one task, also avoiding you to get a "pyramid effect". So something like this should be good for your use-case:
var async = require('async');
gulp.task('yeah', function (cb) {
async.series([
function (next) {
gulp.src('...')
.pipe(gulp.dest('...')
.on('end', next);
},
function (next) {
gulp.src('...')
.pipe(gulp.dest('...')
.on('end', next);
},
function (next) {
gulp.src('...')
.pipe(gulp.dest('...')
.on('end', next);
}
], cb);
});
That will also allow you to have some error handling and target better where a problem occured.
这篇关于我如何强制大量呼叫同步运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!