吞噬任务是否必须返回任何东西? [英] Does a gulp task have to return anything?
问题描述
在显示使用gulp的在线示例中,有些任务返回流,其他任务不返回。 例如,没有返回:
gulp.task('tsc',function()
{
gulp.src('** / *。ts' )
// ...
});
和相同的代码一起返回:
gulp.task('tsc',function()
{
return gulp.src('** / *。ts')
// ...
});
是否需要返回流?
例如,当没有返回流时:
$ gulp scripts
[21:25:05]使用gulpfile〜/ my-project / gulpfile.js
[21:25:05]开始'tsc'...
[21:25:05]完成' tsc'13 ms后
[21:25:05]启动'scripts'...
[21:25:05] 10 ms后完成'scripts'
[21:25: 05]使用tsc版本1.0.1.0编译TypeScript文件
请注意,脚本
任务取决于 tsc
任务。它报告 tsc
在13毫秒内完成,这绝对是太快而不能被合理地相信。然后,脚本
任务似乎会在很短的时间内启动并完成。最后,由 tsc
执行的实际操作开始。显然, tsc
和脚本
都没有等到编译步骤完成。
当这些任务返回它们的流时,输出看起来相当不同:
$ b
$ gulp脚本
[21:42:25]使用gulpfile〜/ my-project / gulpfile.js
[21:42:25]开始'tsc'...
[21:42: 25]使用tsc版本1.0.1.0编译TypeScript文件
[21:42:32]在6.65之后完成'tsc's
[21:42:32]启动'脚本'...
[21:42:32] 204 ms后完成脚本
并且报告的持续时间符合预期。
In online examples showing usage of gulp, some tasks return the stream and others don't.
For example, without a return:
gulp.task('tsc', function()
{
gulp.src('**/*.ts')
// ...
});
And the same code, with a return:
gulp.task('tsc', function()
{
return gulp.src('**/*.ts')
// ...
});
Is it necessary to return the stream?
If you do not return a stream, then the asynchronous result of each task will not be awaited by its caller, nor any dependent tasks.
For example, when not returning streams:
$ gulp scripts
[21:25:05] Using gulpfile ~/my-project/gulpfile.js
[21:25:05] Starting 'tsc'...
[21:25:05] Finished 'tsc' after 13 ms
[21:25:05] Starting 'scripts'...
[21:25:05] Finished 'scripts' after 10 ms
[21:25:05] Compiling TypeScript files using tsc version 1.0.1.0
Note here that the scripts
task depends upon the tsc
task. It reports that tsc
completes in 13 milliseconds, which is definitely too fast to be reasonably believed. Then the scripts
task appears to start and complete, again in a very small period of time. Finally, the actual operation performed by tsc
commences. Clearly neither tsc
nor scripts
waited for the compilation step to complete.
When these tasks return their streams, the output looks rather different:
$ gulp scripts
[21:42:25] Using gulpfile ~/my-project/gulpfile.js
[21:42:25] Starting 'tsc'...
[21:42:25] Compiling TypeScript files using tsc version 1.0.1.0
[21:42:32] Finished 'tsc' after 6.65 s
[21:42:32] Starting 'scripts'...
[21:42:32] Finished 'scripts' after 204 ms
Here the sequence makes sense, and the reported durations meet expectations.
这篇关于吞噬任务是否必须返回任何东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!