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

Function writeInput

packages/platform-node-shared/src/internal/stream.ts:203–226  ·  view source on GitHub ↗
(
  writable: Writable | NodeJS.WritableStream,
  onFailure: (cause: Cause.Cause<IE>) => Effect.Effect<void>,
  { encoding, endOnDone = true }: FromWritableOptions = {},
  onDone = Effect.void
)

Source from the content-addressed store, hash-verified

201
202/** @internal */
203export const writeInput = <IE, A>(
204 writable: Writable | NodeJS.WritableStream,
205 onFailure: (cause: Cause.Cause<IE>) => Effect.Effect<void>,
206 { encoding, endOnDone = true }: FromWritableOptions = {},
207 onDone = Effect.void
208): AsyncInput.AsyncInputProducer<IE, Chunk.Chunk<A>, unknown> => {
209 const write = writeEffect(writable, encoding)
210 const close = endOnDone
211 ? Effect.async<void>((resume) => {
212 if ("closed" in writable && writable.closed) {
213 resume(Effect.void)
214 } else {
215 writable.once("finish", () => resume(Effect.void))
216 writable.end()
217 }
218 })
219 : Effect.void
220 return {
221 awaitRead: () => Effect.void,
222 emit: write,
223 error: (cause) => Effect.zipRight(close, onFailure(cause)),
224 done: (_) => Effect.zipRight(close, onDone)
225 }
226}
227
228/** @internal */
229export const writeEffect = <A>(

Callers 2

fromWritableChannelFunction · 0.85
fromDuplexFunction · 0.85

Calls 4

writeEffectFunction · 0.85
endMethod · 0.65
resumeFunction · 0.50
onFailureFunction · 0.50

Tested by

no test coverage detected