import { isChannelError } from "@effect/core/io/Cause/errors" /** * @tsplus static effect/core/stream/Channel.Aspects pipeToOrFail * @tsplus pipeable effect/core/stream/Channel pipeToOrFail */ export function pipeToOrFail< Env2, OutElem, OutDone, OutErr2, OutElem2, OutDone2 >( that: Channel ) { return ( self: Channel ): Channel => { const reader: Channel = Channel .readWith( (outElem) => Channel.write(outElem).flatMap(() => reader), (outErr) => Channel.failCauseSync(Cause.die(new ChannelError(outErr))), (outDone) => Channel.succeed(outDone) ) const writer: Channel< Env2, OutErr2, OutElem2, OutDone2, OutErr2, OutElem2, OutDone2 > = Channel.readWithCause( (outElem) => Channel.write(outElem).flatMap(() => writer), (cause) => cause.isDieType() && isChannelError(cause.value) ? Channel.fail(cause.value.error as OutErr2) : Channel.failCause(cause), (outDone) => Channel.succeed(outDone) ) return ((self >> reader) >> that) >> writer } }