Package: effect
Module: Channel
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}`)
})
Signature
declare const failSync: <E>(evaluate: LazyArg<E>) => Channel<never, E, never>
Since v2.0.0