diff options
author | Hubert Argasinski <argasinski.hubert@gmail.com> | 2017-07-08 20:04:36 -0400 |
---|---|---|
committer | Hubert Argasinski <argasinski.hubert@gmail.com> | 2017-07-08 20:04:36 -0400 |
commit | 2b221638899f643a82194711557e6ef4295742c0 (patch) | |
tree | 3d2294ee9fae7799b54169637f27c5fb8edee8c4 | |
parent | d5c391a3d764d3a7c2afdc4d7ae111e85312cfc4 (diff) | |
download | async-2b221638899f643a82194711557e6ef4295742c0.tar.gz |
batch queue.push calls
-rw-r--r-- | lib/internal/queue.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/internal/queue.js b/lib/internal/queue.js index 5e8d4d7..b06f12e 100644 --- a/lib/internal/queue.js +++ b/lib/internal/queue.js @@ -18,6 +18,7 @@ export default function queue(worker, concurrency, payload) { var _worker = wrapAsync(worker); var numRunning = 0; var workersList = []; + var isWaitingForProcessing = false; function _insert(data, insertAtFront, callback) { if (callback != null && typeof callback !== 'function') { @@ -46,7 +47,11 @@ export default function queue(worker, concurrency, payload) { q._tasks.push(item); } } - setImmediate(q.process); + + if (!isWaitingForProcessing) { + isWaitingForProcessing = true; + setImmediate(q.process); + } } function _next(tasks) { @@ -106,6 +111,8 @@ export default function queue(worker, concurrency, payload) { q._tasks.remove(testFn); }, process: function () { + isWaitingForProcessing = false; + // Avoid trying to start too many processing operations. This can occur // when callbacks resolve synchronously (#1267). if (isProcessing) { |