| 83 | }; |
| 84 | |
| 85 | async function close(error) { |
| 86 | const hadError = (error !== undefined) && (error !== null); |
| 87 | const hasThrow = typeof iterator.throw === 'function'; |
| 88 | if (hadError && hasThrow) { |
| 89 | const { value, done } = await iterator.throw(error); |
| 90 | await value; |
| 91 | if (done) { |
| 92 | return; |
| 93 | } |
| 94 | } |
| 95 | if (typeof iterator.return === 'function') { |
| 96 | const { value } = await iterator.return(); |
| 97 | await value; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // There are a lot of duplication here, it's done on purpose for performance |
| 102 | // reasons - avoid await when not needed. |