gulp: gulp seems to hang with async task
hi,
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.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 6
- Comments: 19 (2 by maintainers)
Commits related to this issue
- Hack to get gulp to exit on complete: https://github.com/gulpjs/gulp/issues/167 — committed to crfroehlich/Homunculus by deleted user 9 years ago
@nidheeshdas nice solution.
You can monkey patch watch for cleaner code.
here’s a solution:
process.exit happens only if you are not watching.
This is curious. Can you post your entire gulpfile.js for both scenarios?