From 12bfbcf13fb18fc9d27553b6a4e5700297cb32f5 Mon Sep 17 00:00:00 2001 From: Rui Leite Date: Wed, 10 Dec 2014 18:47:12 +0000 Subject: [PATCH] Add parallel limit. #29 --- lib/iconizr.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/iconizr.js b/lib/iconizr.js index ce60949..e4ed41c 100644 --- a/lib/iconizr.js +++ b/lib/iconizr.js @@ -22,6 +22,7 @@ UglifyJS = require('uglify-js'), mkdirp = require('mkdirp'), chalk = require('chalk'), util = require('util'), +os = require('os'), defaultOptions = { // svg-sprite options spritedir : 'icons', @@ -39,6 +40,9 @@ defaultOptions = { preview : null }; + +var CONCURRENT_TASKS_LIMIT = os.cpus().length * 2; + /** * Restore the temporarily altered configuration options * @@ -224,7 +228,9 @@ Iconizr.prototype._svg2png = function(callback) { if (this._options.verbose) { console.log('Creating PNG versions of %s SVG images (including the sprite) ...', tasks.length); } - async.parallel(tasks, function(error) { callback(error); }); + + // launch talks in parallel with a limit to prevent a flood of process + async.parallelLimit(tasks, CONCURRENT_TASKS_LIMIT, function(error) { callback(error); }); } /**