()
| 140 | // ============================================================================= |
| 141 | |
| 142 | async function testDestroyAsync() { |
| 143 | let returnCalled = false; |
| 144 | async function* gen() { |
| 145 | try { |
| 146 | for (let i = 0; ; i++) { |
| 147 | yield [Buffer.from(`chunk${i}`)]; |
| 148 | } |
| 149 | } finally { |
| 150 | returnCalled = true; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | const readable = toReadable(gen()); |
| 155 | |
| 156 | // Read a couple chunks then destroy |
| 157 | const chunks = []; |
| 158 | await new Promise((resolve, reject) => { |
| 159 | readable.on('data', (chunk) => { |
| 160 | chunks.push(chunk); |
| 161 | if (chunks.length >= 3) { |
| 162 | readable.destroy(); |
| 163 | } |
| 164 | }); |
| 165 | readable.on('close', resolve); |
| 166 | readable.on('error', reject); |
| 167 | }); |
| 168 | |
| 169 | assert.ok(chunks.length >= 3); |
| 170 | assert.ok(returnCalled, 'iterator.return() should have been called'); |
| 171 | } |
| 172 | |
| 173 | // ============================================================================= |
| 174 | // fromStreamIter: destroy while pump is waiting on backpressure |
no test coverage detected