Skip to content

Commit 933ea23

Browse files
committed
Fix obscure unhandled rejection when calling .clear()
No tests as I was unable to reproduce this… Fixes #119
1 parent f41d189 commit 933ea23

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

source/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,14 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
164164
if (!this._isPaused) {
165165
const canInitializeInterval = !this._isIntervalPaused();
166166
if (this._doesIntervalAllowAnother && this._doesConcurrentAllowAnother) {
167+
const job = this._queue.dequeue();
168+
if (!job) {
169+
return false;
170+
}
171+
167172
this.emit('active');
173+
job();
168174

169-
this._queue.dequeue()!();
170175
if (canInitializeInterval) {
171176
this._initializeIntervalIfNeeded();
172177
}

0 commit comments

Comments
 (0)