File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff 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' ;
372371import PQueue from ' p-queue' ;
373372
374373const 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
You can’t perform that action at this time.
0 commit comments