gulp seems to hang with async task
See original GitHub issuehi,
I might be missing something here, but let’s say I define a task as follows.
gulp.task('aaa', function(cb){
http.get('http://www.google.com/index.html', function(res){
gutil.log('in result');
cb();
});
});
If I run this task from default and then invoke gulp from the command line I get
prompt$ gulp
[gulp] Running 'default'...
[gulp] Running 'aaa'...
[gulp] Finished 'default' in 4.9 ms
[gulp] in result
[gulp] Finished 'aaa' in 134 ms
But the process hangs there and I don’t get back to the prompt.
However, If redefine the task as follows, and run it
gulp.task('aaa', function(cb){
setTimeout(cb, 2000);
});
prompt$ gulp
[gulp] Running 'default'...
[gulp] Running 'aaa'...
[gulp] Finished 'default' in 833 μs
[gulp] Finished 'aaa' in 2 s
prompt$
This works as expected and the process terminates.
Not sure what I am missing, but any pointers would be great.
Issue Analytics
- State:
- Created 10 years ago
- Reactions:6
- Comments:19 (2 by maintainers)
Top Results From Across the Web
Gulp [4.0.2] hangs when async function is completed even ...
I have a gulp task that's hanging after completion. Running --verbose on my command tells me that it completed the run, but it...
Read more >Async Completion - gulp.js
When a stream, promise, event emitter, child process, or observable is returned from a task, the success or error informs gulp whether to...
Read more >Gulp watch task never terminates, leads to VS hanging waiting ...
VS hangs, tells me it's busy, and is waiting for the node process to be terminated (without actually instructing it to terminate). I...
Read more >In the name of Gulp - Adventures in brine
Because Gulp tasks are asynchronous (non blocking), the default task has no reason to hang around waiting for all the tasks in the...
Read more >Gulp - a modern approach to asset pipeline for Rails developers
But after long consideration Gulp seems to be the best candidate: It's simple. Gulp operates on streams - your job is to create...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nidheeshdas nice solution.
You can monkey patch watch for cleaner code.
here’s a solution:
process.exit happens only if you are not watching.