diff options
author | Hubert Argasinski <argasinski.hubert@gmail.com> | 2017-07-10 00:17:56 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-10 00:17:56 -0400 |
commit | 4c15dd78be67d1d81c44e6420c6cc41feac5408b (patch) | |
tree | c933b26a08b6d7e553bc71a8820abcf2ce35071d /lib | |
parent | d5c391a3d764d3a7c2afdc4d7ae111e85312cfc4 (diff) | |
download | async-4c15dd78be67d1d81c44e6420c6cc41feac5408b.tar.gz |
Improve `async.queue` start up performance (#1448)
* batch queue.push calls
* add more queue perf suites
* undo dist changes
* prevent overwriting q.process from pausing the queue
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/queue.js | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/internal/queue.js b/lib/internal/queue.js index 5e8d4d7..4f57edb 100644 --- a/lib/internal/queue.js +++ b/lib/internal/queue.js @@ -19,6 +19,7 @@ export default function queue(worker, concurrency, payload) { var numRunning = 0; var workersList = []; + var processingScheduled = false; function _insert(data, insertAtFront, callback) { if (callback != null && typeof callback !== 'function') { throw new Error('task callback must be a function'); @@ -46,7 +47,14 @@ export default function queue(worker, concurrency, payload) { q._tasks.push(item); } } - setImmediate(q.process); + + if (!processingScheduled) { + processingScheduled = true; + setImmediate(function() { + processingScheduled = false; + q.process(); + }); + } } function _next(tasks) { |