Hyperlinkv0.8.0-beta.28

Channel

Channel.runDrainconsteffect/Channel.ts:7724
<OutElem, OutErr, OutDone, Env>(
  self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>
): Effect.Effect<OutDone, OutErr, Env>

Runs a channel and discards all output elements, returning only the final result.

Example (Draining channel output at runtime)

import { Channel, Data } from "effect"

class DrainError extends Data.TaggedError("DrainError")<{
  readonly stage: string
}> {}

// Create a channel that outputs elements and completes with a result
const resultChannel = Channel.fromIterable([1, 2, 3])
const completedChannel = Channel.concatWith(
  resultChannel,
  () => Channel.succeed("completed")
)

// Drain all elements and get only the final result
const drainEffect = Channel.runDrain(completedChannel)

// Effect.runSync(drainEffect) // Returns: "completed"
execution
export const runDrain = <OutElem, OutErr, OutDone, Env>(
  self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>
): Effect.Effect<OutDone, OutErr, Env> => runWith(self, (pull) => Effect.forever(pull, { disableYield: true }))
Referenced by 1 symbols