Hyperlinkv0.8.0-beta.28

Channel

Channel.runHeadconsteffect/Channel.ts:7864
<OutElem, OutErr, OutDone, Env>(
  self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>
): Effect.Effect<Option.Option<OutElem>, OutErr, Env>

Runs a channel until the first output element is available, returning it in an Option.

Details

Returns Option.some with the first output element, or Option.none if the channel completes without emitting output.

execution
Source effect/Channel.ts:786414 lines
export const runHead = <OutElem, OutErr, OutDone, Env>(
  self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>
): Effect.Effect<Option.Option<OutElem>, OutErr, Env> =>
  Effect.suspend(() => {
    let head = Option.none<OutElem>()
    return runWith(self, (pull) =>
      pull.pipe(
        Effect.asSome,
        Effect.flatMap((head_) => {
          head = head_
          return Cause.done()
        })
      ), () => Effect.succeed(head))
  })
Referenced by 1 symbols