Skip to content

Commit

Permalink
Merge 6365fee into a20f78d
Browse files Browse the repository at this point in the history
  • Loading branch information
stringparser committed Sep 19, 2014
2 parents a20f78d + 6365fee commit fc8a607
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
24 changes: 17 additions & 7 deletions bin/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var v8flags = require('v8flags');
var completion = require('../lib/completion');
var argv = require('minimist')(process.argv.slice(2));
var taskTree = require('../lib/taskTree');
var batchThese = require('../lib/batchThese');

// set env var for ORIGINAL cwd
// before anything touches it
Expand Down Expand Up @@ -178,17 +179,26 @@ function logEvents(gulpInst) {
});

gulpInst.on('task_start', function (e) {
// TODO: batch these
// so when 5 tasks start at once it only logs one time with all 5
gutil.log('Starting', '\'' + chalk.cyan(e.task) + '\'...');
var batched = '\'' + chalk.cyan(e.task) + '\'';
// logs once when tasks `start` at the same time
batchThese('start', batched, function(batch){
gutil.log('Starting', batch.join(', '), '...');
});
});

gulpInst.on('task_stop', function (e) {
var time = prettyTime(e.hrDuration);
gutil.log(
'Finished', '\'' + chalk.cyan(e.task) + '\'',
'after', chalk.magenta(time)
);
var batched = '\''+chalk.cyan(e.task) +'\' after '+chalk.magenta(time);
// logs once tasks `stop` at the same time
batchThese('stop', batched, function(batch){
// `stop` events have longer logs
if( batch.length < 3 ){
gutil.log('Finished', batch.join(', ') );
return ;
}
gutil.log('Finished', batch.slice(0, 2).join(', ') + ', ');
gutil.log( batch.slice(2).join(', ') );
});
});

gulpInst.on('task_err', function (e) {
Expand Down
33 changes: 33 additions & 0 deletions lib/batchThese.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

var timer = { }, batch = { };
var limit = {
start : 5
};

function batchThese(name, data, callback){

if(timer[name]){
clearTimeout(timer[name]);
delete timer[name];
}

batch[name] = batch[name] || [];
batch[name].push(data);

var bound = limit[name] || 3;
if( batch[name].length > bound ){
callback(batch[name]);
delete batch[name];
return ;
}

timer[name] = setTimeout(function(){
if( batch[name] ){
callback(batch[name]);
}
delete batch[name];
});
}

module.exports = batchThese;

0 comments on commit fc8a607

Please sign in to comment.