単純な例:2つのgulpタスクがあります(2番目のタスクは最初のタスクから評価される必要があります)。 setTimeout):遅延されたgulpタスクの戻り値を他の1つで正しく使用する方法
var gulp = require("gulp");
var values = undefined;
gulp.task("one", function(cb) {
console.log(values);
setTimeout(function() {
console.log('First finnished!!!');
values = "Vovan and Alex";
}, 1000);
cb(values);
})
gulp.task("two", ["one"], function() {
console.log(values);
console.log("Second's done!")
})
gulp.task("default", ["one", "two"]);
以下に結果として得られる:
[18:24:26] Using gulpfile ~/workspace/gulpfile.js [18:24:26] Starting 'one'... undefined [18:24:26] Finished 'one' after 1.58 ms [18:24:26] Starting 'two'... undefined Second's done! [18:24:26] Finished 'two' after 302 μs [18:24:26] Starting 'default'... [18:24:26] Finished 'default' after 17 μs First finnished!!!
よく壊れています。エラーが1秒後に '[18:43:58]'でエラーします。 [18:43:58]エラー:VovanとAlex ' –
これはgulpがストリームを期待しているからです文字列の配列を渡します。私は答えの終わりにそれを言いました。 – ssube
..だから、どのようなコードがそのように見えますか? –