<A, E>(self: Dequeue<A, E>): Effect<number>Returns the current number of buffered messages in the queue.
Details
Completed queues report a size of 0.
Example (Checking queue size)
import { Cause, Effect, Option, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(10)
// Check size of empty queue
const size1 = yield* Queue.size(queue)
console.log(size1) // 0
// Add some messages
yield* Queue.offerAll(queue, [1, 2, 3, 4, 5])
// Check size after adding messages
const size2 = yield* Queue.size(queue)
console.log(size2) // 5
// End the queue
yield* Queue.end(queue)
// Size of ended queue is 0
const size3 = yield* Queue.size(queue)
console.log(size3) // 0
})export const const size: <A, E>(
self: Dequeue<A, E>
) => Effect<number>
Returns the current number of buffered messages in the queue.
Details
Completed queues report a size of 0.
Example (Checking queue size)
import { Cause, Effect, Option, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(10)
// Check size of empty queue
const size1 = yield* Queue.size(queue)
console.log(size1) // 0
// Add some messages
yield* Queue.offerAll(queue, [1, 2, 3, 4, 5])
// Check size after adding messages
const size2 = yield* Queue.size(queue)
console.log(size2) // 5
// End the queue
yield* Queue.end(queue)
// Size of ended queue is 0
const size3 = yield* Queue.size(queue)
console.log(size3) // 0
})
size = <function (type parameter) A in <A, E>(self: Dequeue<A, E>): Effect<number>A, function (type parameter) E in <A, E>(self: Dequeue<A, E>): Effect<number>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<number>A, function (type parameter) E in <A, E>(self: Dequeue<A, E>): Effect<number>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<number> => import internalEffectinternalEffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect.Effect<A>
sync(() => const sizeUnsafe: <A, E>(
self: Dequeue<A, E>
) => number
Returns the current number of buffered messages in the queue synchronously.
When to use
Use when you need an immediate Queue size snapshot for diagnostics or
internals and do not need the read wrapped in Effect.
Details
Completed queues report a size of 0. This unsafe operation reads the queue
state directly without Effect wrapping.
Example (Checking queue size synchronously)
import { Cause, Effect, Option, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(10)
// Check size of empty queue
const size1 = Queue.sizeUnsafe(queue)
console.log(size1) // 0
// Add some messages
Queue.offerUnsafe(queue, 1)
Queue.offerUnsafe(queue, 2)
Queue.offerUnsafe(queue, 3)
// Check size after adding messages
const size2 = Queue.sizeUnsafe(queue)
console.log(size2) // 3
// End the queue
Queue.endUnsafe(queue)
// Size of ended queue is 0
const size3 = Queue.sizeUnsafe(queue)
console.log(size3) // 0
})
sizeUnsafe(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))