<A, E>(self: Dequeue<A, E>): Effect<Array<A>, Pull.ExcludeDone<E>>Takes and returns all currently buffered messages without waiting for more.
Details
Returns an empty array when the queue is empty or has completed normally. If the queue has failed, the effect fails with the queue's error.
Example (Clearing queued values)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number>(10)
// Add several messages
yield* Queue.offerAll(queue, [1, 2, 3, 4, 5])
// Clear all messages from the queue
const messages = yield* Queue.clear(queue)
console.log(messages) // [1, 2, 3, 4, 5]
// Queue is now empty
const size = yield* Queue.size(queue)
console.log(size) // 0
// Clearing empty queue returns empty array
const empty = yield* Queue.clear(queue)
console.log(empty) // []
})export const const clear: <A, E>(
self: Dequeue<A, E>
) => Effect<Array<A>, Pull.ExcludeDone<E>>
Takes and returns all currently buffered messages without waiting for more.
Details
Returns an empty array when the queue is empty or has completed normally. If
the queue has failed, the effect fails with the queue's error.
Example (Clearing queued values)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number>(10)
// Add several messages
yield* Queue.offerAll(queue, [1, 2, 3, 4, 5])
// Clear all messages from the queue
const messages = yield* Queue.clear(queue)
console.log(messages) // [1, 2, 3, 4, 5]
// Queue is now empty
const size = yield* Queue.size(queue)
console.log(size) // 0
// Clearing empty queue returns empty array
const empty = yield* Queue.clear(queue)
console.log(empty) // []
})
clear = <function (type parameter) A in <A, E>(self: Dequeue<A, E>): Effect<Array<A>, Pull.ExcludeDone<E>>A, function (type parameter) E in <A, E>(self: Dequeue<A, E>): Effect<Array<A>, Pull.ExcludeDone<E>>E>(self: Dequeue<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 Dequeue<out A, out E = never>A Dequeue is a queue that can be taken from.
Details
This interface represents the read-only part of a Queue, allowing you to take
elements from the queue but not offer elements to it.
Example (Taking through dequeue handles)
import { Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<string, never>(10)
// A Dequeue can only take elements
const dequeue: Queue.Dequeue<string> = queue
// Pre-populate the queue
yield* Queue.offerAll(queue, ["a", "b", "c"])
// Take elements using dequeue interface
const item = yield* Queue.take(dequeue)
console.log(item) // "a"
})
Companion namespace containing type-level metadata for the Dequeue
read-only queue interface.
Dequeue<function (type parameter) A in <A, E>(self: Dequeue<A, E>): Effect<Array<A>, Pull.ExcludeDone<E>>A, function (type parameter) E in <A, E>(self: Dequeue<A, E>): Effect<Array<A>, Pull.ExcludeDone<E>>E>): interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<interface Array<T>Array<function (type parameter) A in <A, E>(self: Dequeue<A, E>): Effect<Array<A>, Pull.ExcludeDone<E>>A>, import PullPull.type ExcludeDone<E> = E extends Done<any>
? never
: E
Excludes Cause.Done completion signals from an error type union.
When to use
Use to describe the ordinary error type that remains after Cause.Done
completion signals have been handled or filtered out of an error union.
ExcludeDone<function (type parameter) E in <A, E>(self: Dequeue<A, E>): Effect<Array<A>, Pull.ExcludeDone<E>>E>> =>
import internalEffectinternalEffect.const suspend: <A, E, R>(
evaluate: LazyArg<Effect.Effect<A, E, R>>
) => Effect.Effect<A, E, R>
suspend(() => {
if (self: Dequeue<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.Dequeue<out A, out E = never>.state: Queue.State<any, any>state._tag: "Open" | "Closing" | "Done"_tag === "Done") {
if (import PullPull.const isDoneCause: <E>(
cause: Cause.Cause<E>
) => boolean
Checks whether a Cause contains any done errors.
When to use
Use when you need to test whether a pull failure cause represents normal
completion and only need a boolean result.
isDoneCause(self: Dequeue<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.Dequeue<out A, out E = never>.state: {
readonly _tag: "Done";
readonly exit: Failure<never, any>;
}
state.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.Failure<never, any>.cause: Cause.Cause<E>(property) Failure<never, any>.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)) {
return import internalEffectinternalEffect.const succeed: <A>(
value: A
) => Effect.Effect<A>
succeed([])
}
return self: Dequeue<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.Dequeue<out A, out E = never>.state: {
readonly _tag: "Done";
readonly exit: Failure<never, any>;
}
state.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 const messages: any[]messages = const takeAllUnsafe: <A, E>(
self: Dequeue<A, E>
) => Array<any>
takeAllUnsafe(self: Dequeue<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 releaseCapacity: <A, E>(
self: Dequeue<A, E>
) => boolean
releaseCapacity(self: Dequeue<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)
return import internalEffectinternalEffect.const succeed: <A>(
value: A
) => Effect.Effect<A>
succeed(const messages: any[]messages)
})