(iterators, primaryError)
| 514 | } |
| 515 | |
| 516 | async function cleanupIterators(iterators, primaryError) { |
| 517 | let cleanupError; |
| 518 | await SafePromiseAllReturnVoid(iterators, async (iterator) => { |
| 519 | if (iterator.return) { |
| 520 | try { |
| 521 | await iterator.return(); |
| 522 | } catch (err) { |
| 523 | // Keep the first cleanup error encountered. |
| 524 | cleanupError ??= err; |
| 525 | } |
| 526 | } |
| 527 | }); |
| 528 | if (cleanupError !== undefined) { |
| 529 | if (primaryError !== undefined) { |
| 530 | // Both a primary error and a cleanup error occurred. |
| 531 | // Wrap in SuppressedError so neither is lost: |
| 532 | // .error = primaryError, .suppressed = cleanupError. |
| 533 | // eslint-disable-next-line no-restricted-syntax |
| 534 | throw new SuppressedError(primaryError, cleanupError); |
| 535 | } |
| 536 | // No primary error - the cleanup error is the only error. |
| 537 | throw cleanupError; |
| 538 | } |
| 539 | if (primaryError !== undefined) { |
| 540 | throw primaryError; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | module.exports = { |
| 545 | array, |
no test coverage detected
searching dependent graphs…