Hyperlinkv0.8.0-beta.28

Channel

Channel.toPullconsteffect/Channel.ts:8053
<OutElem, OutErr, OutDone, Env>(
  self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>
): Effect.Effect<
  Pull.Pull<OutElem, OutErr, OutDone>,
  never,
  Env | Scope.Scope
>

Converts a channel to a scoped Pull for low-level consumption.

Details

The effect requires a Scope. The returned pull should be consumed only while that scope remains open. Pulls are serialized so only one pull is evaluated at a time.

Example (Converting channels to pulls)

import { Channel, Data, Effect } from "effect"

class PullError extends Data.TaggedError("PullError")<{
  readonly step: string
}> {}

// Create a channel
const numbersChannel = Channel.fromIterable([1, 2, 3])

// Convert to Pull within a scope
const pullEffect = Effect.scoped(
  Channel.toPull(numbersChannel)
)

// Use the Pull to manually consume elements
destructors
Source effect/Channel.ts:805322 lines
export const toPull: <OutElem, OutErr, OutDone, Env>(
  self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>
) => Effect.Effect<
  Pull.Pull<OutElem, OutErr, OutDone>,
  never,
  Env | Scope.Scope
> = Effect.fnUntraced(
  function*<OutElem, OutErr, OutDone, Env>(
    self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>
  ) {
    const semaphore = Semaphore.makeUnsafe(1)
    const context = yield* Effect.context<Env | Scope.Scope>()
    const scope = Context.get(context, Scope.Scope)
    const pull = yield* toTransform(self)(Cause.done(), scope)
    return pull.pipe(
      Effect.provideContext(context),
      semaphore.withPermits(1)
    )
  },
  // ensure errors are redirected to the pull effect
  Effect.catchCause((cause) => Effect.succeed(Effect.failCause(cause)))
) as any
Referenced by 2 symbols