Skip to content

Queue

A Queue is a lightweight in-memory queue built on Effect with composable and transparent back-pressure. It is fully asynchronous (no locks or blocking), purely-functional and type-safe.

A Queue<A> stores values of type A and provides two fundamental operations:

  • Queue.offer: This operation adds a value of type A to the Queue.
  • Queue.take: It removes and returns the oldest value from the Queue.

Here’s an example demonstrating these basic operations:

1
import {
import Effect
Effect
,
import Queue
Queue
} from "effect"
2
3
const
const program: Effect.Effect<number, never, never>
program
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<Queue.Queue<number>, never, never>> | YieldWrap<Effect.Effect<number, never, never>> | YieldWrap<Effect.Effect<...>>, number>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
4
const
const queue: Queue.Queue<number>
queue
= yield*
import Queue
Queue
.
const bounded: <number>(requestedCapacity: number) => Effect.Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<number>(100)
5
// Add 1 to the queue
6
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 1)
7
// Retrieve and remove the oldest value
8
const
const value: number
value
= yield*
import Queue
Queue
.
const take: <number>(self: Queue.Dequeue<number>) => Effect.Effect<number, never, never>

Takes the oldest value in the queue. If the queue is empty, this will return a computation that resumes when an item has been added to the queue.

take
(
const queue: Queue.Queue<number>
queue
)
9
return
const value: number
value
10
})
11
12
import Effect
Effect
.
const runPromise: <number, never>(effect: Effect.Effect<number, never, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<number>

Runs an `Effect` workflow, returning a `Promise` which resolves with the result of the workflow or rejects with an error.

runPromise
(
const program: Effect.Effect<number, never, never>
program
).
(method) Promise<number>.then<void, never>(onfulfilled?: ((value: number) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
)
13
// Output: 1

A Queue can have bounded (limited capacity) or unbounded storage. Depending on your requirements, you can choose from various strategies to handle new values when the queue reaches its capacity.

A bounded queue provides back-pressure when it’s full. This means that if the queue is full, any attempt to add more items will be suspended until there’s space available.

1
import {
import Queue
Queue
} from "effect"
2
3
// Creating a bounded queue with a capacity of 100
4
const
const boundedQueue: Effect<Queue.Queue<number>, never, never>
boundedQueue
=
import Queue
Queue
.
const bounded: <number>(requestedCapacity: number) => Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<number>(100)

A dropping queue simply drops new items when it’s full. It doesn’t wait for space to become available.

1
import {
import Queue
Queue
} from "effect"
2
3
// Creating a dropping queue with a capacity of 100
4
const
const droppingQueue: Effect<Queue.Queue<number>, never, never>
droppingQueue
=
import Queue
Queue
.
const dropping: <number>(requestedCapacity: number) => Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue` with the dropping strategy. When the capacity of the queue is reached, new elements will be dropped and the old elements will remain. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

dropping
<number>(100)

A sliding queue removes old items when it’s full to accommodate new ones.

1
import {
import Queue
Queue
} from "effect"
2
3
// Creating a sliding queue with a capacity of 100
4
const
const slidingQueue: Effect<Queue.Queue<number>, never, never>
slidingQueue
=
import Queue
Queue
.
const sliding: <number>(requestedCapacity: number) => Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue` with the sliding strategy. When the capacity of the queue is reached, new elements will be added and the old elements will be dropped. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

sliding
<number>(100)

An unbounded queue has no capacity limit.

1
import {
import Queue
Queue
} from "effect"
2
3
// Creating an unbounded queue
4
const
const unboundedQueue: Effect<Queue.Queue<number>, never, never>
unboundedQueue
=
import Queue
Queue
.
const unbounded: <number>() => Effect<Queue.Queue<number>, never, never>

Creates a new unbounded `Queue`.

unbounded
<number>()

To add a value to the queue, you can use the Queue.offer operation:

1
import {
import Effect
Effect
,
import Queue
Queue
} from "effect"
2
3
const
const program: Effect.Effect<void, never, never>
program
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<Queue.Queue<number>, never, never>> | YieldWrap<Effect.Effect<boolean, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
4
const
const queue: Queue.Queue<number>
queue
= yield*
import Queue
Queue
.
const bounded: <number>(requestedCapacity: number) => Effect.Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<number>(100)
5
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 1) // put 1 in the queue
6
})

If you’re using a back-pressured queue and it’s full, the offer operation might suspend. In such cases, you can use Effect.fork to wait in a different execution context (fiber).

1
import {
import Effect
Effect
,
import Queue
Queue
,
import Fiber
Fiber
} from "effect"
2
3
const
const program: Effect.Effect<void, never, never>
program
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<Queue.Queue<number>, never, never>> | YieldWrap<Effect.Effect<boolean, never, never>> | YieldWrap<Effect.Effect<...>> | YieldWrap<...>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
4
const
const queue: Queue.Queue<number>
queue
= yield*
import Queue
Queue
.
const bounded: <number>(requestedCapacity: number) => Effect.Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<number>(1)
5
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 1)
6
// The following offer will be suspended because the queue is full
7
const
const fiber: Fiber.RuntimeFiber<boolean, never>
fiber
= yield*
import Effect
Effect
.
const fork: <boolean, never, never>(self: Effect.Effect<boolean, never, never>) => Effect.Effect<Fiber.RuntimeFiber<boolean, never>, never, never>

Returns an effect that forks this effect into its own separate fiber, returning the fiber immediately, without waiting for it to begin executing the effect. You can use the `fork` method whenever you want to execute an effect in a new fiber, concurrently and without "blocking" the fiber executing other effects. Using fibers can be tricky, so instead of using this method directly, consider other higher-level methods, such as `raceWith`, `zipPar`, and so forth. The fiber returned by this method has methods to interrupt the fiber and to wait for it to finish executing the effect. See `Fiber` for more information. Whenever you use this method to launch a new fiber, the new fiber is attached to the parent fiber's scope. This means when the parent fiber terminates, the child fiber will be terminated as well, ensuring that no fibers leak. This behavior is called "auto supervision", and if this behavior is not desired, you may use the `forkDaemon` or `forkIn` methods.

fork
(
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 2))
8
yield*
import Queue
Queue
.
const take: <number>(self: Queue.Dequeue<number>) => Effect.Effect<number, never, never>

Takes the oldest value in the queue. If the queue is empty, this will return a computation that resumes when an item has been added to the queue.

take
(
const queue: Queue.Queue<number>
queue
)
9
yield*
import Fiber
Fiber
.
const join: <boolean, never>(self: Fiber.Fiber<boolean, never>) => Effect.Effect<boolean, never, never>

Joins the fiber, which suspends the joining fiber until the result of the fiber has been determined. Attempting to join a fiber that has erred will result in a catchable error. Joining an interrupted fiber will result in an "inner interruption" of this fiber, unlike interruption triggered by another fiber, "inner interruption" can be caught and recovered.

join
(
const fiber: Fiber.RuntimeFiber<boolean, never>
fiber
)
10
})

You can also add multiple values at once using Queue.offerAll:

1
import {
import Effect
Effect
,
import Queue
Queue
,
import Array
Array
} from "effect"
2
3
const
const program: Effect.Effect<number, never, never>
program
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<Queue.Queue<number>, never, never>> | YieldWrap<Effect.Effect<number, never, never>> | YieldWrap<Effect.Effect<...>>, number>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
4
const
const queue: Queue.Queue<number>
queue
= yield*
import Queue
Queue
.
const bounded: <number>(requestedCapacity: number) => Effect.Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<number>(100)
5
const
const items: [number, ...number[]]
items
=
import Array
Array
.
const range: (start: number, end: number) => Array.NonEmptyArray<number>

Return a `NonEmptyArray` containing a range of integers, including both endpoints.

range
(1, 10)
6
yield*
import Queue
Queue
.
const offerAll: <number>(self: Queue.Enqueue<number>, iterable: Iterable<number>) => Effect.Effect<boolean> (+1 overload)

For Bounded Queue: uses the `BackPressure` Strategy, places the values in the queue and always returns true. If the queue has reached capacity, then the fiber performing the `offerAll` will be suspended until there is room in the queue. For Unbounded Queue: Places all values in the queue and returns true. For Sliding Queue: uses `Sliding` Strategy If there is room in the queue, it places the values otherwise it removes the old elements and enqueues the new ones. Always returns true. For Dropping Queue: uses `Dropping` Strategy, It places the values in the queue but if there is no room it will not enqueue them and return false.

offerAll
(
const queue: Queue.Queue<number>
queue
,
const items: [number, ...number[]]
items
)
7
return yield*
import Queue
Queue
.
const size: <number>(self: Queue.Enqueue<number> | Queue.Dequeue<number>) => Effect.Effect<number>

Retrieves the size of the queue, which is equal to the number of elements in the queue. This may be negative if fibers are suspended waiting for elements to be added to the queue.

size
(
const queue: Queue.Queue<number>
queue
)
8
})
9
10
import Effect
Effect
.
const runPromise: <number, never>(effect: Effect.Effect<number, never, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<number>

Runs an `Effect` workflow, returning a `Promise` which resolves with the result of the workflow or rejects with an error.

runPromise
(
const program: Effect.Effect<number, never, never>
program
).
(method) Promise<number>.then<void, never>(onfulfilled?: ((value: number) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
)
11
// Output: 10

The Queue.take operation removes the oldest item from the queue and returns it. If the queue is empty, it will suspend and resume only when an item is added to the queue. You can also use Effect.fork to wait for the value in a different execution context (fiber).

1
import {
import Effect
Effect
,
import Queue
Queue
,
import Fiber
Fiber
} from "effect"
2
3
const
const oldestItem: Effect.Effect<string, never, never>
oldestItem
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<Queue.Queue<string>, never, never>> | YieldWrap<Effect.Effect<Fiber.RuntimeFiber<string, never>, never, never>> | YieldWrap<...> | YieldWrap<...>, string>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
4
const
const queue: Queue.Queue<string>
queue
= yield*
import Queue
Queue
.
const bounded: <string>(requestedCapacity: number) => Effect.Effect<Queue.Queue<string>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<string>(100)
5
// The following take will be suspended because the queue is empty
6
const
const fiber: Fiber.RuntimeFiber<string, never>
fiber
= yield*
import Effect
Effect
.
const fork: <string, never, never>(self: Effect.Effect<string, never, never>) => Effect.Effect<Fiber.RuntimeFiber<string, never>, never, never>

Returns an effect that forks this effect into its own separate fiber, returning the fiber immediately, without waiting for it to begin executing the effect. You can use the `fork` method whenever you want to execute an effect in a new fiber, concurrently and without "blocking" the fiber executing other effects. Using fibers can be tricky, so instead of using this method directly, consider other higher-level methods, such as `raceWith`, `zipPar`, and so forth. The fiber returned by this method has methods to interrupt the fiber and to wait for it to finish executing the effect. See `Fiber` for more information. Whenever you use this method to launch a new fiber, the new fiber is attached to the parent fiber's scope. This means when the parent fiber terminates, the child fiber will be terminated as well, ensuring that no fibers leak. This behavior is called "auto supervision", and if this behavior is not desired, you may use the `forkDaemon` or `forkIn` methods.

fork
(
import Queue
Queue
.
const take: <string>(self: Queue.Dequeue<string>) => Effect.Effect<string, never, never>

Takes the oldest value in the queue. If the queue is empty, this will return a computation that resumes when an item has been added to the queue.

take
(
const queue: Queue.Queue<string>
queue
))
7
yield*
import Queue
Queue
.
const offer: <string>(self: Queue.Enqueue<string>, value: string) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<string>
queue
, "something")
8
const
const value: string
value
= yield*
import Fiber
Fiber
.
const join: <string, never>(self: Fiber.Fiber<string, never>) => Effect.Effect<string, never, never>

Joins the fiber, which suspends the joining fiber until the result of the fiber has been determined. Attempting to join a fiber that has erred will result in a catchable error. Joining an interrupted fiber will result in an "inner interruption" of this fiber, unlike interruption triggered by another fiber, "inner interruption" can be caught and recovered.

join
(
const fiber: Fiber.RuntimeFiber<string, never>
fiber
)
9
return
const value: string
value
10
})
11
12
import Effect
Effect
.
const runPromise: <string, never>(effect: Effect.Effect<string, never, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<string>

Runs an `Effect` workflow, returning a `Promise` which resolves with the result of the workflow or rejects with an error.

runPromise
(
const oldestItem: Effect.Effect<string, never, never>
oldestItem
).
(method) Promise<string>.then<void, never>(onfulfilled?: ((value: string) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
)
13
// Output: something

You can retrieve the first item using Queue.poll. If the queue is empty, you’ll get None; otherwise, the top item will be wrapped in Some.

1
import {
import Effect
Effect
,
import Queue
Queue
} from "effect"
2
3
const
const polled: Effect.Effect<Option<number>, never, never>
polled
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<Queue.Queue<number>, never, never>> | YieldWrap<Effect.Effect<Option<number>, never, never>> | YieldWrap<...>, Option<...>>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
4
const
const queue: Queue.Queue<number>
queue
= yield*
import Queue
Queue
.
const bounded: <number>(requestedCapacity: number) => Effect.Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<number>(100)
5
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 10)
6
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 20)
7
const
const head: Option<number>
head
= yield*
import Queue
Queue
.
const poll: <number>(self: Queue.Dequeue<number>) => Effect.Effect<Option<number>, never, never>

Returns the first value in the `Queue` as a `Some<A>`, or `None` if the queue is empty.

poll
(
const queue: Queue.Queue<number>
queue
)
8
return
const head: Option<number>
head
9
})
10
11
import Effect
Effect
.
const runPromise: <Option<number>, never>(effect: Effect.Effect<Option<number>, never, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<Option<...>>

Runs an `Effect` workflow, returning a `Promise` which resolves with the result of the workflow or rejects with an error.

runPromise
(
const polled: Effect.Effect<Option<number>, never, never>
polled
).
(method) Promise<Option<number>>.then<void, never>(onfulfilled?: ((value: Option<number>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
)
12
/*
13
Output:
14
{
15
_id: "Option",
16
_tag: "Some",
17
value: 10
18
}
19
*/

You can retrieve multiple items at once using Queue.takeUpTo. If the queue doesn’t have enough items to return, it will return all the available items without waiting for more offers.

1
import {
import Effect
Effect
,
import Queue
Queue
} from "effect"
2
3
const
const polled: Effect.Effect<Chunk<number>, never, never>
polled
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<Queue.Queue<number>, never, never>> | YieldWrap<Effect.Effect<Chunk<number>, never, never>> | YieldWrap<...>, Chunk<...>>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
4
const
const queue: Queue.Queue<number>
queue
= yield*
import Queue
Queue
.
const bounded: <number>(requestedCapacity: number) => Effect.Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<number>(100)
5
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 10)
6
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 20)
7
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 30)
8
const
const chunk: Chunk<number>
chunk
= yield*
import Queue
Queue
.
const takeUpTo: <number>(self: Queue.Dequeue<number>, max: number) => Effect.Effect<Chunk<number>, never, never> (+1 overload)

Takes up to max number of values from the queue.

takeUpTo
(
const queue: Queue.Queue<number>
queue
, 2)
9
return
const chunk: Chunk<number>
chunk
10
})
11
12
import Effect
Effect
.
const runPromise: <Chunk<number>, never>(effect: Effect.Effect<Chunk<number>, never, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<Chunk<number>>

Runs an `Effect` workflow, returning a `Promise` which resolves with the result of the workflow or rejects with an error.

runPromise
(
const polled: Effect.Effect<Chunk<number>, never, never>
polled
).
(method) Promise<Chunk<number>>.then<void, never>(onfulfilled?: ((value: Chunk<number>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
)
13
/*
14
Output:
15
{
16
_id: "Chunk",
17
values: [ 10, 20 ]
18
}
19
*/

Similarly, you can retrieve all items at once using Queue.takeAll. It returns immediately, providing an empty collection if the queue is empty.

1
import {
import Effect
Effect
,
import Queue
Queue
} from "effect"
2
3
const
const polled: Effect.Effect<Chunk<number>, never, never>
polled
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<Queue.Queue<number>, never, never>> | YieldWrap<Effect.Effect<Chunk<number>, never, never>> | YieldWrap<...>, Chunk<...>>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
4
const
const queue: Queue.Queue<number>
queue
= yield*
import Queue
Queue
.
const bounded: <number>(requestedCapacity: number) => Effect.Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<number>(100)
5
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 10)
6
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 20)
7
yield*
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
const queue: Queue.Queue<number>
queue
, 30)
8
const
const chunk: Chunk<number>
chunk
= yield*
import Queue
Queue
.
const takeAll: <number>(self: Queue.Dequeue<number>) => Effect.Effect<Chunk<number>, never, never>

Takes all the values in the queue and returns the values. If the queue is empty returns an empty collection.

takeAll
(
const queue: Queue.Queue<number>
queue
)
9
return
const chunk: Chunk<number>
chunk
10
})
11
12
import Effect
Effect
.
const runPromise: <Chunk<number>, never>(effect: Effect.Effect<Chunk<number>, never, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<Chunk<number>>

Runs an `Effect` workflow, returning a `Promise` which resolves with the result of the workflow or rejects with an error.

runPromise
(
const polled: Effect.Effect<Chunk<number>, never, never>
polled
).
(method) Promise<Chunk<number>>.then<void, never>(onfulfilled?: ((value: Chunk<number>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
)
13
/*
14
Output:
15
{
16
_id: "Chunk",
17
values: [ 10, 20, 30 ]
18
}
19
*/

With Queue.shutdown, you can interrupt all fibers that are suspended on offer* or take*. It also empties the queue and causes all future offer* and take* calls to terminate immediately.

1
import {
import Effect
Effect
,
import Queue
Queue
,
import Fiber
Fiber
} from "effect"
2
3
const
const program: Effect.Effect<void, never, never>
program
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<void, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<YieldWrap<Effect.Effect<void, never, never>>, void, never>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
4
const
const queue: Queue.Queue<number>
queue
= yield*
import Queue
Queue
.
const bounded: <number>(requestedCapacity: number) => Effect.Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<number>(3)
5
const
const fiber: Fiber.RuntimeFiber<number, never>
fiber
= yield*
import Effect
Effect
.
const fork: <number, never, never>(self: Effect.Effect<number, never, never>) => Effect.Effect<Fiber.RuntimeFiber<number, never>, never, never>

Returns an effect that forks this effect into its own separate fiber, returning the fiber immediately, without waiting for it to begin executing the effect. You can use the `fork` method whenever you want to execute an effect in a new fiber, concurrently and without "blocking" the fiber executing other effects. Using fibers can be tricky, so instead of using this method directly, consider other higher-level methods, such as `raceWith`, `zipPar`, and so forth. The fiber returned by this method has methods to interrupt the fiber and to wait for it to finish executing the effect. See `Fiber` for more information. Whenever you use this method to launch a new fiber, the new fiber is attached to the parent fiber's scope. This means when the parent fiber terminates, the child fiber will be terminated as well, ensuring that no fibers leak. This behavior is called "auto supervision", and if this behavior is not desired, you may use the `forkDaemon` or `forkIn` methods.

fork
(
import Queue
Queue
.
const take: <number>(self: Queue.Dequeue<number>) => Effect.Effect<number, never, never>

Takes the oldest value in the queue. If the queue is empty, this will return a computation that resumes when an item has been added to the queue.

take
(
const queue: Queue.Queue<number>
queue
))
6
yield*
import Queue
Queue
.
const shutdown: <number>(self: Queue.Enqueue<number> | Queue.Dequeue<number>) => Effect.Effect<void>

Interrupts any fibers that are suspended on `offer` or `take`. Future calls to `offer*` and `take*` will be interrupted immediately.

shutdown
(
const queue: Queue.Queue<number>
queue
) // will interrupt fiber
7
yield*
import Fiber
Fiber
.
const join: <number, never>(self: Fiber.Fiber<number, never>) => Effect.Effect<number, never, never>

Joins the fiber, which suspends the joining fiber until the result of the fiber has been determined. Attempting to join a fiber that has erred will result in a catchable error. Joining an interrupted fiber will result in an "inner interruption" of this fiber, unlike interruption triggered by another fiber, "inner interruption" can be caught and recovered.

join
(
const fiber: Fiber.RuntimeFiber<number, never>
fiber
) // will terminate
8
})

You can use Queue.awaitShutdown to execute an effect when the queue is shut down. This function waits until the queue is shut down, and if it’s already shut down, it resumes immediately.

1
import {
import Effect
Effect
,
import Queue
Queue
,
import Fiber
Fiber
,
import Console
Console
} from "effect"
2
3
const
const program: Effect.Effect<void, never, never>
program
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<void, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<YieldWrap<Effect.Effect<void, never, never>>, void, never>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
4
const
const queue: Queue.Queue<number>
queue
= yield*
import Queue
Queue
.
const bounded: <number>(requestedCapacity: number) => Effect.Effect<Queue.Queue<number>, never, never>

Makes a new bounded `Queue`. When the capacity of the queue is reached, any additional calls to `offer` will be suspended until there is more room in the queue. **Note**: When possible use only power of 2 capacities; this will provide better performance by utilising an optimised version of the underlying `RingBuffer`.

bounded
<number>(3)
5
const
const fiber: Fiber.RuntimeFiber<void, never>
fiber
= yield*
import Effect
Effect
.
const fork: <void, never, never>(self: Effect.Effect<void, never, never>) => Effect.Effect<Fiber.RuntimeFiber<void, never>, never, never>

Returns an effect that forks this effect into its own separate fiber, returning the fiber immediately, without waiting for it to begin executing the effect. You can use the `fork` method whenever you want to execute an effect in a new fiber, concurrently and without "blocking" the fiber executing other effects. Using fibers can be tricky, so instead of using this method directly, consider other higher-level methods, such as `raceWith`, `zipPar`, and so forth. The fiber returned by this method has methods to interrupt the fiber and to wait for it to finish executing the effect. See `Fiber` for more information. Whenever you use this method to launch a new fiber, the new fiber is attached to the parent fiber's scope. This means when the parent fiber terminates, the child fiber will be terminated as well, ensuring that no fibers leak. This behavior is called "auto supervision", and if this behavior is not desired, you may use the `forkDaemon` or `forkIn` methods.

fork
(
6
import Queue
Queue
.
const awaitShutdown: <number>(self: Queue.Enqueue<number> | Queue.Dequeue<number>) => Effect.Effect<void>

Waits until the queue is shutdown. The `Effect` returned by this method will not resume until the queue has been shutdown. If the queue is already shutdown, the `Effect` will resume right away.

awaitShutdown
(
const queue: Queue.Queue<number>
queue
).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
pipe
(
7
import Effect
Effect
.
const andThen: <Effect.Effect<void, never, never>>(f: Effect.Effect<void, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<void, E, R> (+3 overloads)

Executes a sequence of two actions, typically two `Effect`s, where the second action can depend on the result of the first action. The `that` action can take various forms: - a value - a function returning a value - a promise - a function returning a promise - an effect - a function returning an effect

andThen
(
import Console
Console
.
const log: (...args: ReadonlyArray<any>) => Effect.Effect<void>
log
("shutting down"))
8
)
9
)
10
yield*
import Queue
Queue
.
const shutdown: <number>(self: Queue.Enqueue<number> | Queue.Dequeue<number>) => Effect.Effect<void>

Interrupts any fibers that are suspended on `offer` or `take`. Future calls to `offer*` and `take*` will be interrupted immediately.

shutdown
(
const queue: Queue.Queue<number>
queue
)
11
yield*
import Fiber
Fiber
.
const join: <void, never>(self: Fiber.Fiber<void, never>) => Effect.Effect<void, never, never>

Joins the fiber, which suspends the joining fiber until the result of the fiber has been determined. Attempting to join a fiber that has erred will result in a catchable error. Joining an interrupted fiber will result in an "inner interruption" of this fiber, unlike interruption triggered by another fiber, "inner interruption" can be caught and recovered.

join
(
const fiber: Fiber.RuntimeFiber<void, never>
fiber
)
12
})
13
14
import Effect
Effect
.
const runPromise: <void, never>(effect: Effect.Effect<void, never, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<void>

Runs an `Effect` workflow, returning a `Promise` which resolves with the result of the workflow or rejects with an error.

runPromise
(
const program: Effect.Effect<void, never, never>
program
)
15
// Output: shutting down

In some situations, you may need specific parts of your code to have exclusive capabilities, such as only offering values (Enqueue) or only taking values (Dequeue) from a queue. Effect provides a straightforward way to achieve this.

All operations related to offering values are defined by the Enqueue interface. Here’s an example of how to use it:

1
import {
import Queue
Queue
} from "effect"
2
3
const
const send: (offerOnlyQueue: Queue.Enqueue<number>, value: number) => Effect<boolean, never, never>
send
= (
(parameter) offerOnlyQueue: Queue.Enqueue<number>
offerOnlyQueue
:
import Queue
Queue
.
interface Enqueue<in A>
Enqueue
<number>,
(parameter) value: number
value
: number) => {
4
// This enqueue can only be used to offer values
5
6
// @ts-expect-error
7
import Queue
Queue
.
const take: <unknown>(self: Queue.Dequeue<unknown>) => Effect<unknown, never, never>

Takes the oldest value in the queue. If the queue is empty, this will return a computation that resumes when an item has been added to the queue.

take
(
(parameter) offerOnlyQueue: Queue.Enqueue<number>
offerOnlyQueue
)
8
9
// Ok
10
return
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
(parameter) offerOnlyQueue: Queue.Enqueue<number>
offerOnlyQueue
,
(parameter) value: number
value
)
11
}

Similarly, all operations related to taking values are defined by the Dequeue interface. Here’s an example:

1
import {
import Queue
Queue
} from "effect"
2
3
const
const receive: (takeOnlyQueue: Queue.Dequeue<number>) => Effect<number, never, never>
receive
= (
(parameter) takeOnlyQueue: Queue.Dequeue<number>
takeOnlyQueue
:
import Queue
Queue
.
interface Dequeue<out A>
Dequeue
<number>) => {
4
// This dequeue can only be used to take values
5
6
// @ts-expect-error
7
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
(parameter) takeOnlyQueue: Queue.Dequeue<number>
takeOnlyQueue
, 1)
8
9
// Ok
10
return
import Queue
Queue
.
const take: <number>(self: Queue.Dequeue<number>) => Effect<number, never, never>

Takes the oldest value in the queue. If the queue is empty, this will return a computation that resumes when an item has been added to the queue.

take
(
(parameter) takeOnlyQueue: Queue.Dequeue<number>
takeOnlyQueue
)
11
}

The Queue type extends both Enqueue and Dequeue, allowing you to conveniently pass it to different parts of your code where you want to enforce either Enqueue or Dequeue behavior:

1
import {
import Effect
Effect
,
import Queue
Queue
} from "effect"
2
3
const
const send: (offerOnlyQueue: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean, never, never>
send
= (
(parameter) offerOnlyQueue: Queue.Enqueue<number>
offerOnlyQueue
:
import Queue
Queue
.
interface Enqueue<in A>
Enqueue
<number>,
(parameter) value: number
value
: number) => {
4
return
import Queue
Queue
.
const offer: <number>(self: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean> (+1 overload)

Places one value in the queue.

offer
(
(parameter) offerOnlyQueue: Queue.Enqueue<number>
offerOnlyQueue
,
(parameter) value: number
value
)
5
}
6
7
const
const receive: (takeOnlyQueue: Queue.Dequeue<number>) => Effect.Effect<number, never, never>
receive
= (
(parameter) takeOnlyQueue: Queue.Dequeue<number>
takeOnlyQueue
:
import Queue
Queue
.
interface Dequeue<out A>
Dequeue
<number>) => {
8
return
import Queue
Queue
.
const take: <number>(self: Queue.Dequeue<number>) => Effect.Effect<number, never, never>

Takes the oldest value in the queue. If the queue is empty, this will return a computation that resumes when an item has been added to the queue.

take
(
(parameter) takeOnlyQueue: Queue.Dequeue<number>
takeOnlyQueue
)
9
}
10
11
const
const program: Effect.Effect<void, never, never>
program
=
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<Queue.Queue<number>, never, never>> | YieldWrap<Effect.Effect<boolean, never, never>> | YieldWrap<Effect.Effect<...>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(function* () {
12
const
const queue: Queue.Queue<number>
queue
= yield*
import Queue
Queue
.
const unbounded: <number>() => Effect.Effect<Queue.Queue<number>, never, never>

Creates a new unbounded `Queue`.

unbounded
<number>()
13
14
// Offer values to the queue
15
yield*
const send: (offerOnlyQueue: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean, never, never>
send
(
const queue: Queue.Queue<number>
queue
, 1)
16
yield*
const send: (offerOnlyQueue: Queue.Enqueue<number>, value: number) => Effect.Effect<boolean, never, never>
send
(
const queue: Queue.Queue<number>
queue
, 2)
17
18
// Take values from the queue
19
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(yield*
const receive: (takeOnlyQueue: Queue.Dequeue<number>) => Effect.Effect<number, never, never>
receive
(
const queue: Queue.Queue<number>
queue
))
20
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(yield*
const receive: (takeOnlyQueue: Queue.Dequeue<number>) => Effect.Effect<number, never, never>
receive
(
const queue: Queue.Queue<number>
queue
))
21
})
22
23
import Effect
Effect
.
const runPromise: <void, never>(effect: Effect.Effect<void, never, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<void>

Runs an `Effect` workflow, returning a `Promise` which resolves with the result of the workflow or rejects with an error.

runPromise
(
const program: Effect.Effect<void, never, never>
program
)
24
/*
25
Output:
26
1
27
2
28
*/