MCPcopy Index your code
hub / github.com/nodejs/node / createAsyncIterator

Function createAsyncIterator

lib/internal/streams/readable.js:1383–1431  ·  view source on GitHub ↗
(stream, options)

Source from the content-addressed store, hash-verified

1381}
1382
1383async 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
1433let composeImpl;
1434

Callers 1

streamToAsyncIteratorFunction · 0.85

Calls 7

eosFunction · 0.85
aggregateTwoErrorsFunction · 0.85
cleanupFunction · 0.70
callbackFunction · 0.50
onMethod · 0.45
readMethod · 0.45
offMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…