Skip to content

Commit

Permalink
Fix obscure unhandled rejection when calling .clear()
Browse files Browse the repository at this point in the history
No tests as I was unable to reproduce this…

Fixes #119
  • Loading branch information
sindresorhus committed Oct 11, 2020
1 parent f41d189 commit 933ea23
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,14 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
if (!this._isPaused) {
const canInitializeInterval = !this._isIntervalPaused();
if (this._doesIntervalAllowAnother && this._doesConcurrentAllowAnother) {
const job = this._queue.dequeue();
if (!job) {
return false;
}

this.emit('active');
job();

this._queue.dequeue()!();
if (canInitializeInterval) {
this._initializeIntervalIfNeeded();
}
Expand Down

0 comments on commit 933ea23

Please sign in to comment.