Hyperlinkv0.8.0-beta.28

Channel

Channel.failSyncconsteffect/Channel.ts:988
<E>(evaluate: LazyArg<E>): Channel<never, E, never>

Constructs a channel that fails immediately with the specified lazily evaluated error.

When to use

Use when the error value should be computed each time the channel runs instead of when the channel is constructed.

Example (Failing with a lazy error)

import { Channel } from "effect"

// Create a channel that fails with a lazily computed error
const failedChannel = Channel.failSync(() => {
  console.log("Computing error...")
  return new Error("Computed at runtime")
})

// The error computation is deferred until the channel runs
let attempts = 0
const conditionalError = Channel.failSync(() => {
  attempts += 1
  return `Error after attempt ${attempts}`
})

// Use with expensive error construction
const expensiveError = Channel.failSync(() => {
  const requestId = "request-123"
  return new Error(`Failed while processing ${requestId}`)
})
constructors
Source effect/Channel.ts:9881 lines
export const failSync = <E>(evaluate: LazyArg<E>): Channel<never, E, never> => fromPull(Effect.failSync(evaluate))
Referenced by 1 symbols