Skip to content

Commit 5ecfda8

Browse files
committed
Clarify error event docs
Fixes #171
1 parent c0bcd36 commit 5ecfda8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

readme.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,9 @@ queue.add(() => Promise.resolve('hello, world!'));
365365

366366
#### error
367367

368-
Emitted if an item throws an error.
368+
Emitted if an item throws an error. The promise returned by `add()` is still rejected, so you must handle both.
369369

370370
```js
371-
import delay from 'delay';
372371
import PQueue from 'p-queue';
373372

374373
const queue = new PQueue({concurrency: 2});
@@ -377,7 +376,10 @@ queue.on('error', error => {
377376
console.error(error);
378377
});
379378

380-
queue.add(() => Promise.reject(new Error('error')));
379+
// Handle the promise to prevent unhandled rejection
380+
queue.add(() => Promise.reject(new Error('error'))).catch(() => {
381+
// Error already handled by event listener
382+
});
381383
```
382384

383385
#### empty

0 commit comments

Comments
 (0)