Hyperlinkv0.8.0-beta.28

Channel

Channel.failconsteffect/Channel.ts:949
<E>(error: E): Channel<never, E, never>

Constructs a channel that fails immediately with the specified error.

Example (Failing with an error)

import { Channel } from "effect"

// Create a channel that fails with a string error
const failedChannel = Channel.fail("Something went wrong")

// Create a channel that fails with a custom error
class CustomError extends Error {
  constructor(message: string) {
    super(message)
    this.name = "CustomError"
  }
}
const customErrorChannel = Channel.fail(new CustomError("Custom error"))

// Use in error handling by piping to another channel
const channelWithFallback = Channel.concatWith(
  failedChannel,
  () => Channel.succeed("fallback value")
)
constructors
Source effect/Channel.ts:9491 lines
export const fail = <E>(error: E): Channel<never, E, never> => fromPull(Effect.succeed(Effect.fail(error)))
Referenced by 8 symbols