首页 > 其他 > 详细

gulp: Did you forget to signal async completion?处理新思路

时间:2021-05-12 20:37:46      阅读:25      评论:0      收藏:0      [点我收藏+]

背景
学习gulp的前端自动化构建,按照示例代码,跑了一个简单的task,控制台打出如下提示:
The following tasks did not complete: testGulp
Did you forget to signal async completion?

查阅Stack Overflow,表示有五种解决办法,在这里提供一种更简单的改法。

问题重现
原代码:

1 const gulp = require(‘gulp‘);
2     gulp.task(‘testGulp‘, () => {
3     console.log(‘Hello World!‘);
4 });

控制台报错:
The following tasks did not complete: testGulp
Did you forget to signal async completion?

解决方法,使用 async 和 await。

修改后代码

1 const gulp = require(‘gulp‘);
2     gulp.task(‘script‘, async() => {
3     await console.log(‘Hello World!‘);
4 });


控制台输出正常

1 $ gulp script
2 [16:29:06] Using gulpfile D:\workspace\my-project\gulpfile.js
3 [16:29:06] Starting ‘script‘...
4 [16:29:06] Finished ‘script‘ after 8.84 ms


附官方方法
在不使用文件流的情况下,向task的函数里传入一个名叫done的回调函数,以结束task,如下代码所示:

1 gulp.task(‘testGulp‘, done => {
2     console.log(‘Hello World!‘);
3     done();
4 });


done回调函数的作用是在task完成时通知Gulp(而不是返回一个流),而task里的所有其他功能都纯粹依赖Node来实现。
————————————————
版权声明:本文为CSDN博主「奋斗的小绿萝」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_40817115/article/details/81079507

gulp: Did you forget to signal async completion?处理新思路

原文:https://www.cnblogs.com/chunboli/p/14760400.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!