diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-02-13 00:04:27 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-02-13 00:04:27 +0100 |
commit | 7c8386986919f611dcdaaf917bf0c24fabcfe3a4 (patch) | |
tree | d73e830143ab6bc60721d489cb9ff947e3f21ba0 /lib/template.js | |
parent | 57d5c23eafbce5dc3b5351a4a5a6520434c717fd (diff) | |
download | gitbook-7c8386986919f611dcdaaf917bf0c24fabcfe3a4.zip gitbook-7c8386986919f611dcdaaf917bf0c24fabcfe3a4.tar.gz gitbook-7c8386986919f611dcdaaf917bf0c24fabcfe3a4.tar.bz2 |
Limit concurrent blocks processed
Diffstat (limited to 'lib/template.js')
-rw-r--r-- | lib/template.js | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/template.js b/lib/template.js index 91b4850..08e1877 100644 --- a/lib/template.js +++ b/lib/template.js @@ -6,6 +6,7 @@ var nunjucks = require("nunjucks"); var git = require("./utils/git"); var stringUtils = require("./utils/string"); var fs = require("./utils/fs"); +var batch = require("./utils/batch"); var pkg = require("../package.json"); @@ -368,16 +369,19 @@ TemplateEngine.prototype.postProcess = function(content) { return Q(content) .then(that.replaceBlocks) .then(function(content) { - return Q.all(_.map(that.blocks, function(blk, blkId) { - return Q() - .then(function() { - if (!blk.post) return Q(); - return blk.post(); - }) - .then(function() { - delete that.blocks[blkId]; - }); - })) + return batch.execEach(that.blocks, { + max: 20, + fn: function(blk, blkId) { + return Q() + .then(function() { + if (!blk.post) return Q(); + return blk.post(); + }) + .then(function() { + delete that.blocks[blkId]; + }); + } + }) .thenResolve(content); }); }; |