MCPcopy Create free account
hub / github.com/Effect-TS/effect / loop

Function loop

packages/platform/node-shared/src/NodeSink.ts:139–171  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

137 // Let Node finish auto-destruction before attempting another write.
138 const onFinish = () => dispatcher.scheduleTask(loop, 0)
139 const loop = () => {
140 options.writable.off("drain", loop)
141 options.writable.off("finish", onFinish)
142 for (; i < chunk.length;) {
143 if (cancelled) {
144 return
145 }
146 const success = options.writable.write(chunk[i++], options.encoding as any, (error) => {
147 if (!error) return
148 if (options.writable.closed) {
149 // Closed streams can reject writes through the callback only;
150 // there is no pending destruction to wait for.
151 onError(error)
152 } else {
153 // Let Node initiate auto-destruction before failure cleanup
154 // checks whether an error event is still pending.
155 dispatcher.scheduleTask(() => onError(error), 0)
156 }
157 })
158 if (!success) {
159 if (!cancelled) {
160 options.writable.once("drain", loop)
161 // A normally finished writable will never emit drain. Resume
162 // the loop so any remaining writes can report their errors.
163 options.writable.once("finish", onFinish)
164 }
165 return
166 }
167 }
168 if (!cancelled) {
169 resume(Effect.void)
170 }
171 }
172 loop()
173 return Effect.sync(() => {
174 cancelled = true

Callers 1

pullIntoWritableFunction · 0.70

Calls 5

onceMethod · 0.80
onErrorFunction · 0.70
writeMethod · 0.65
scheduleTaskMethod · 0.65
resumeFunction · 0.50

Tested by

no test coverage detected