Last active
August 29, 2015 13:56
-
-
Save AntouanK/9216499 to your computer and use it in GitHub Desktop.
Promises in gulp.js for exiting after many async(?) tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // gulpfile.js section | |
| // | |
| // ... | |
| // | |
| var gulp = require('gulp'), | |
| Q = require('q'), | |
| fs = require('fs'), | |
| brands = ['gitHub', 'joyent', 'fractal']; | |
| // check the available brands folders | |
| gulp.task('checkBrands', function(done, res){ | |
| var deferred = Q.defer(), | |
| brandsLeft = brands.length; | |
| brands.forEach(function(brand){ | |
| var exists = fs.existsSync(brand); | |
| console.log(brand + ' ' + (exists ? 'found' : 'not found')); | |
| if(exists){ | |
| existingBrands.push(brand); | |
| } | |
| brandsLeft -= 1; | |
| if(brandsLeft === 0){ | |
| deferred.resolve(); | |
| } | |
| }); | |
| return deferred.promise; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment