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

Function fromWritableChannel

packages/platform/node-shared/src/NodeSink.ts:54–70  ·  view source on GitHub ↗
(
  options: {
    readonly evaluate: LazyArg<Writable | NodeJS.WritableStream>
    readonly onError: (error: unknown) => E
    readonly endOnDone?: boolean | undefined
    readonly encoding?: BufferEncoding | undefined
  }
)

Source from the content-addressed store, hash-verified

52 * @since 4.0.0
53 */
54export const fromWritableChannel = <IE, E, A = Uint8Array | string>(
55 options: {
56 readonly evaluate: LazyArg<Writable | NodeJS.WritableStream>
57 readonly onError: (error: unknown) => E
58 readonly endOnDone?: boolean | undefined
59 readonly encoding?: BufferEncoding | undefined
60 }
61): Channel.Channel<never, IE | E, void, NonEmptyReadonlyArray<A>, IE> =>
62 Channel.fromTransform((pull: Pull.Pull<NonEmptyReadonlyArray<A>, IE, unknown>) => {
63 const writable = options.evaluate() as Writable
64 const write = pullIntoWritable({ ...options, writable, pull })
65 return Effect.succeed(
66 options.endOnDone === false
67 ? write
68 : Effect.onError(write, (cause) => Pull.isDoneCause(cause) ? Effect.void : releaseWritable(writable))
69 )
70 })
71
72// Destroy the writable and wait for destruction to settle, keeping any
73// destruction error handled.

Callers 1

fromWritableFunction · 0.85

Calls 5

pullIntoWritableFunction · 0.85
releaseWritableFunction · 0.85
onErrorMethod · 0.80
evaluateMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected