MCPcopy
hub / github.com/Effect-TS/effect / writeEffect

Function writeEffect

packages/platform-node-shared/src/internal/stream.ts:229–252  ·  view source on GitHub ↗
(
  writable: Writable | NodeJS.WritableStream,
  encoding?: BufferEncoding
)

Source from the content-addressed store, hash-verified

227
228/** @internal */
229export const writeEffect = <A>(
230 writable: Writable | NodeJS.WritableStream,
231 encoding?: BufferEncoding
232) =>
233(chunk: Chunk.Chunk<A>) =>
234 chunk.length === 0 ?
235 Effect.void :
236 Effect.async<void>((resume) => {
237 const iterator = chunk[Symbol.iterator]()
238 let next = iterator.next()
239 function loop() {
240 const item = next
241 next = iterator.next()
242 const success = writable.write(item.value, encoding as any)
243 if (next.done) {
244 resume(Effect.void)
245 } else if (success) {
246 loop()
247 } else {
248 writable.once("drain", loop)
249 }
250 }
251 loop()
252 })
253
254const unsafeReadableRead = <A, E>(
255 readable: Readable | NodeJS.ReadableStream,

Callers 1

writeInputFunction · 0.85

Calls 2

loopFunction · 0.70
nextMethod · 0.65

Tested by

no test coverage detected