(
writable: Writable | NodeJS.WritableStream,
onFailure: (cause: Cause.Cause<IE>) => Effect.Effect<void>,
{ encoding, endOnDone = true }: FromWritableOptions = {},
onDone = Effect.void
)
| 201 | |
| 202 | /** @internal */ |
| 203 | export 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 */ |
| 229 | export const writeEffect = <A>( |
no test coverage detected