diff options
author | Hubert Argasinski <argasinski.hubert@gmail.com> | 2022-02-14 02:11:47 -0500 |
---|---|---|
committer | Hubert Argasinski <argasinski.hubert@gmail.com> | 2022-02-14 02:11:47 -0500 |
commit | 05fd72164dfdc10703edb993839f41b10cbca516 (patch) | |
tree | de7d5cf1bdc5d9b9279765c521aa19b836125571 | |
parent | b8d1115888c335bdf55d53fa0a943859420c259c (diff) | |
download | async-schedule-drain.tar.gz |
add a guard to the task callback drainschedule-drain
-rw-r--r-- | lib/internal/queue.js | 4 | ||||
-rw-r--r-- | test/queue.js | 6 |
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/internal/queue.js b/lib/internal/queue.js index fdbabbc..fffea99 100644 --- a/lib/internal/queue.js +++ b/lib/internal/queue.js @@ -115,8 +115,10 @@ export default function queue(worker, concurrency, payload) { trigger('unsaturated') } - if (q.idle()) { + if (q.idle() && !drainScheduled) { + drainScheduled = true trigger('drain') + drainScheduled = false } q.process(); }; diff --git a/test/queue.js b/test/queue.js index bd71b05..c99380e 100644 --- a/test/queue.js +++ b/test/queue.js @@ -690,8 +690,8 @@ describe('queue', function(){ }); it('should not schedule another drain call if one is running', (done) => { - const q = async.queue(() => { - throw new Error('should not be called') + const q = async.queue((task, cb) => { + cb(null, task); }) let numCalled = 0 @@ -702,7 +702,7 @@ describe('queue', function(){ numCalled++ q.push([]) }) - q.push([]) + q.push('foo') setTimeout(() => { expect(numCalled).to.equal(1) |