Reputation: 75686
This example is from the docs, but the task itself does not exit when running from the command line. It runs and finishes, but does NOT return to the shell like every other gulp task I use.
var Q = require('q');
gulp.task('somename', function() {
var deferred = Q.defer();
// do async stuff
setTimeout(function() {
deferred.resolve();
}, 1);
return deferred.promise;
});
How do I get this task to exit back to the shell? I realize I can explicitly called process.exit(0)
but this breaks the chainability.
Upvotes: 0
Views: 2562
Reputation: 6322
I notice that you dont have a callback in your function but the "Works for me" answer does. When I removed the callback from my function, it did not exit automatically, replicating your problem.
Add a callback... ie:
var Q = require('q');
gulp.task('somename', function(callback) {
var deferred = Q.defer();
// do async stuff
setTimeout(function() {
deferred.resolve();
}, 1);
return deferred.promise;
});
Upvotes: 1
Reputation: 15417
Works for me, again :)
var gulp = require('gulp');
var Q = require('q');
gulp.task('somename', function(callback) {
var deferred = Q.defer();
setTimeout(function() {
deferred.resolve();
}, 1);
return deferred.promise;
});
Results:
∴ gulp somename
[13:35:51] Using gulpfile ~/Desktop/promise-test/gulpfile.js
[13:35:51] Starting 'somename'...
[13:35:51] Finished 'somename' after 1.69 ms
∴
Versions:
∴ node -v
v0.10.33
∴ npm -v
2.1.5
∴ gulp -v
[13:37:34] CLI version 3.8.9
[13:37:34] Local version 3.8.9
Upvotes: 2