(stream, options)
| 1381 | } |
| 1382 | |
| 1383 | async function* createAsyncIterator(stream, options) { |
| 1384 | let callback = nop; |
| 1385 | |
| 1386 | function next(resolve) { |
| 1387 | if (this === stream) { |
| 1388 | callback(); |
| 1389 | callback = nop; |
| 1390 | } else { |
| 1391 | callback = resolve; |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | stream.on('readable', next); |
| 1396 | |
| 1397 | let error; |
| 1398 | const cleanup = eos(stream, { writable: false }, (err) => { |
| 1399 | error = err ? aggregateTwoErrors(error, err) : null; |
| 1400 | callback(); |
| 1401 | callback = nop; |
| 1402 | }); |
| 1403 | |
| 1404 | try { |
| 1405 | while (true) { |
| 1406 | const chunk = stream.destroyed ? null : stream.read(); |
| 1407 | if (chunk !== null) { |
| 1408 | yield chunk; |
| 1409 | } else if (error) { |
| 1410 | throw error; |
| 1411 | } else if (error === null) { |
| 1412 | return; |
| 1413 | } else { |
| 1414 | await new Promise(next); |
| 1415 | } |
| 1416 | } |
| 1417 | } catch (err) { |
| 1418 | error = aggregateTwoErrors(error, err); |
| 1419 | throw error; |
| 1420 | } finally { |
| 1421 | if ( |
| 1422 | (error || options?.destroyOnReturn !== false) && |
| 1423 | (error === undefined || stream._readableState.autoDestroy) |
| 1424 | ) { |
| 1425 | destroyImpl.destroyer(stream, null); |
| 1426 | } else { |
| 1427 | stream.off('readable', next); |
| 1428 | cleanup(); |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | let composeImpl; |
| 1434 |
no test coverage detected
searching dependent graphs…