Skip to content

Commit

Permalink
Merge pull request #45 from pwalczyszyn/master
Browse files Browse the repository at this point in the history
Calling done() when all jobs are finished
  • Loading branch information
johnnyhalife committed Mar 11, 2014
2 parents fe7d924 + b2f34e3 commit d8e54c6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tasks/grunt-cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = function(grunt) {
engine = require('./lib/engine'),
options = this.options(),
key,
supportedTypes = Object.create(ParserConfig.supportedTypes);
supportedTypes = Object.create(ParserConfig.supportedTypes),
activeJobs = 0;

for(key in options.supportedTypes){
if(options.supportedTypes.hasOwnProperty(key)) {
Expand All @@ -38,6 +39,9 @@ module.exports = function(grunt) {

grunt.log.subhead('cdn:' + type + ' - ' + filepath);

// Incrementing counter of active jobs
activeJobs++;

if (supportedTypes[type] === "html") {
job = engine.html(options);
} else if (supportedTypes[type] === "css") {
Expand All @@ -50,7 +54,11 @@ module.exports = function(grunt) {
}).on("end", function (result) {
// write the contents to destination
grunt.file.write(destfile, result);
done();

activeJobs--; // The job is done
if (activeJobs === 0) { // Checking if all jobs are done
done();
}
});
});
});
Expand Down

0 comments on commit d8e54c6

Please sign in to comment.