MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / pullAlgorithm

Function pullAlgorithm

examples/io/streams/modules/streams.js:1000–1053  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

998 let branch2;
999 let cancelPromise = createPromise();
1000 function pullAlgorithm() {
1001 if (reading) {
1002 readAgain = true;
1003 return Promise.resolve(undefined);
1004 }
1005 reading = true;
1006 const readRequest = {
1007 chunkSteps: chunk => {
1008 queueMicrotask(() => {
1009 readAgain = false;
1010 const chunk1 = chunk;
1011 const chunk2 = chunk;
1012 // if (canceled2 === false && cloneForBranch2 === true) {
1013 // try {
1014 // chunk2 = StructuredClone(chunk2);
1015 // }
1016 // catch (e) {
1017 // ReadableByteStreamControllerError(branch1.controller, e);
1018 // ReadableByteStreamControllerError(branch2.controller, e);
1019 // resolvePromise(cancelPromise, ReadableStreamCancel(stream, e));
1020 // return;
1021 // }
1022 // }
1023 if (canceled1 === false) {
1024 ReadableStreamDefaultControllerEnqueue(branch1.controller, chunk1);
1025 }
1026 if (canceled2 === false) {
1027 ReadableStreamDefaultControllerEnqueue(branch2.controller, chunk2);
1028 }
1029 reading = false;
1030 if (readAgain === true) {
1031 pullAlgorithm();
1032 }
1033 });
1034 },
1035 closeSteps: () => {
1036 reading = false;
1037 if (canceled1 === false) {
1038 ReadableStreamDefaultControllerClose(branch1.controller);
1039 }
1040 if (canceled2 === false) {
1041 ReadableStreamDefaultControllerClose(branch2.controller);
1042 }
1043 if (canceled1 === false || canceled2 === false) {
1044 resolvePromise(cancelPromise, undefined);
1045 }
1046 },
1047 errorSteps: () => {
1048 reading = false;
1049 }
1050 };
1051 ReadableStreamDefaultReaderRead(reader, readRequest);
1052 return Promise.resolve(undefined);
1053 }
1054 function cancel1Algorithm(reason) {
1055 canceled1 = true;
1056 reason1 = reason;

Callers

nothing calls this directly

Tested by

no test coverage detected