<A, E>(self: Enqueue<A, E>, cause: Cause<E>): booleanFails the queue with a cause synchronously. If the queue is already done, false is
returned.
When to use
Use when queue completion must be driven from synchronous internals while
preserving the full failure Cause.
Gotchas
This is an unsafe operation that directly modifies the queue without Effect wrapping.
Example (Failing queues with a cause synchronously)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, string>(10)
// Create a cause and fail the queue synchronously
const cause = Cause.fail("Processing error")
const failed = Queue.failCauseUnsafe(queue, cause)
console.log(failed) // true
// The queue is now done with the specified failure cause
console.log(queue.state._tag) // "Done"
})export const const failCauseUnsafe: <A, E>(
self: Enqueue<A, E>,
cause: Cause<E>
) => boolean
Fails the queue with a cause synchronously. If the queue is already done, false is
returned.
When to use
Use when queue completion must be driven from synchronous internals while
preserving the full failure Cause.
Gotchas
This is an unsafe operation that directly modifies the queue without Effect wrapping.
Example (Failing queues with a cause synchronously)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, string>(10)
// Create a cause and fail the queue synchronously
const cause = Cause.fail("Processing error")
const failed = Queue.failCauseUnsafe(queue, cause)
console.log(failed) // true
// The queue is now done with the specified failure cause
console.log(queue.state._tag) // "Done"
})
failCauseUnsafe = <function (type parameter) A in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): booleanA, function (type parameter) E in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): booleanE>(self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self: interface Enqueue<in A, in E = never>An Enqueue is a queue that can be offered to.
Details
This interface represents the write-only part of a Queue, allowing you to offer
elements to the queue but not take elements from it.
Example (Offering through enqueue handles)
import { Effect, Queue } from "effect"
// Function that only needs write access to a queue
const producer = (enqueue: Queue.Enqueue<string>) =>
Effect.gen(function*() {
yield* Queue.offer(enqueue, "hello")
yield* Queue.offerAll(enqueue, ["world", "!"])
})
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<string>(10)
yield* producer(queue)
})
Companion namespace containing type-level metadata for the Enqueue
write-only queue interface.
Enqueue<function (type parameter) A in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): booleanA, function (type parameter) E in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): booleanE>, cause: Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause: interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
isInterruptReason
.
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): booleanE>): boolean => {
if (self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self.Enqueue<in A, in E = never>.state: Queue.State<any, any>state._tag: "Open" | "Closing" | "Done"_tag !== "Open") {
return false
}
const const exit: Exit<never, E>exit = import corecore.const exitFailCause: <E>(
cause: Cause.Cause<E>
) => Exit.Exit<never, E>
exitFailCause(cause: Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause)
const const fail: Failure<never, E>const fail: {
_tag: "Failure";
cause: Cause.Cause<E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
fail = import internalEffectinternalEffect.const exitZipRight: {
<A2, E2>(that: Exit.Exit<A2, E2>): <A, E>(
self: Exit.Exit<A, E>
) => Exit.Exit<A2, E | E2>
<A, E, A2, E2>(
self: Exit.Exit<A, E>,
that: Exit.Exit<A2, E2>
): Exit.Exit<A2, E | E2>
}
exitZipRight(const exit: Exit<never, E>exit, const exitFailDone: Failure<
never,
Done<void>
>
const exitFailDone: {
_tag: "Failure";
cause: Cause.Cause<E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
exitFailDone) as interface Failure<out A, out E>A failed Exit containing a Cause.
When to use
Use when working with the failed branch of an Exit after narrowing with
isFailure
. Access the cause via the cause property after
narrowing.
Details
The Cause<E> may contain typed errors, defects, or interruptions.
Example (Accessing the failure cause)
import { Exit } from "effect"
const failure = Exit.fail("something went wrong")
if (Exit.isFailure(failure)) {
console.log(failure._tag) // "Failure"
console.log(failure.cause) // Cause representing the error
}
Failure<never, function (type parameter) E in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): booleanE>
if (
self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self.Enqueue<in A, in E = never>.state: {
readonly _tag: "Open";
readonly takers: Set<(_: Effect<void, any, never>) => void>;
readonly offers: Set<Queue.OfferEntry<any>>;
readonly awaiters: Set<(_: Effect<void, any, never>) => void>;
}
state.offers: Set<Queue.OfferEntry<any>>offers.Set<T>.size: numbersize === 0 &&
self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self.Enqueue<in A, in E = never>.messages: MutableList.MutableList<any>(property) Enqueue<in A, in E = never>.messages: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
messages.MutableList<any>.length: numberlength === 0
) {
const finalize: <A, E>(
self: Enqueue<A, E> | Dequeue<A, E>,
exit: Failure<never, E>
) => void
finalize(self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self, const fail: Failure<never, E>const fail: {
_tag: "Failure";
cause: Cause.Cause<E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
fail)
return true
}
self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self.Enqueue<in A, in E = never>.state: Queue.State<any, any>state = { ...self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self.Enqueue<in A, in E = never>.state: {
readonly _tag: "Open";
readonly takers: Set<(_: Effect<void, any, never>) => void>;
readonly offers: Set<Queue.OfferEntry<any>>;
readonly awaiters: Set<(_: Effect<void, any, never>) => void>;
}
state, _tag: "Closing"_tag: "Closing", exit: Failure<never, E>(property) exit: {
_tag: "Failure";
cause: Cause.Cause<E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
exit: const fail: Failure<never, E>const fail: {
_tag: "Failure";
cause: Cause.Cause<E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
fail }
return true
}