Skip to content

Schedule Combinators

Schedules define stateful, possibly effectful, recurring schedules of events, and compose in a variety of ways. Combinators allow us to take schedules and combine them together to get other schedules.

To demonstrate the functionality of different schedules, we will be working with the following helper:

declare const log: <A, Out>(
action: Effect.Effect<A>,
schedule: Schedule.Schedule<Out, void>
) => void
Click to see the implementation
1
import {
import Effect
Effect
,
import Schedule
Schedule
,
import TestClock
TestClock
,
import Fiber
Fiber
,
import TestContext
TestContext
} from "effect"
2
3
let
let start: number
start
= 0
4
let
let i: number
i
= 0
5
6
const
const log: <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>) => void
log
= <
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
,
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
>(
7
(parameter) action: Effect.Effect<A, never, never>
action
:
import Effect
Effect
.
interface Effect<out A, out E = never, out R = never> namespace Effect

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`. `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
<
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
>,
8
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
:
import Schedule
Schedule
.
interface Schedule<out Out, in In = unknown, out R = never> namespace Schedule

A `Schedule<Out, In, R>` defines a recurring schedule, which consumes values of type `In`, and which returns values of type `Out`. Schedules are defined as a possibly infinite set of intervals spread out over time. Each interval defines a window in which recurrence is possible. When schedules are used to repeat or retry effects, the starting boundary of each interval produced by a schedule is used as the moment when the effect will be executed again. Schedules compose in the following primary ways: - Union: performs the union of the intervals of two schedules - Intersection: performs the intersection of the intervals of two schedules - Sequence: concatenates the intervals of one schedule onto another In addition, schedule inputs and outputs can be transformed, filtered (to terminate a schedule early in response to some input or output), and so forth. A variety of other operators exist for transforming and combining schedules, and the companion object for `Schedule` contains all common types of schedules, both for performing retrying, as well as performing repetition.

Schedule
<
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, void>
9
) => {
10
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* () {
11
const
const fiber: Fiber.RuntimeFiber<[Out, number], never>
fiber
:
import Fiber
Fiber
.
interface RuntimeFiber<out A, out E = never>

A runtime fiber that is executing an effect. Runtime fibers have an identity and a trace.

RuntimeFiber
<[
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, number]> = yield*
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<A, never, never>> | YieldWrap<Effect.Effect<number, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(
12
function* () {
13
yield*
(parameter) action: Effect.Effect<A, never, never>
action
14
const
const now: number
now
= yield*
import TestClock
TestClock
.
const currentTimeMillis: Effect.Effect<number, never, never>

Accesses the current time of a `TestClock` instance in the context in milliseconds.

currentTimeMillis
15
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
(
16
let i: number
i
=== 0
17
? `delay: ${
const now: number
now
-
let start: number
start
}`
18
:
let i: number
i
=== 10
19
? "..."
20
: `#${
let i: number
i
} delay: ${
const now: number
now
-
let start: number
start
}`
21
)
22
let i: number
i
++
23
let start: number
start
=
const now: number
now
24
}
25
).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<[Out, number], never, never>, Effect.Effect<Fiber.RuntimeFiber<[Out, number], never>, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
26
import Effect
Effect
.
const repeat: <[Out, number], void, never>(schedule: Schedule.Schedule<[Out, number], void, never>) => <E, R>(self: Effect.Effect<void, E, R>) => Effect.Effect<[Out, number], E, R> (+3 overloads)

The `repeat` function returns a new effect that repeats the given effect according to a specified schedule or until the first failure. The scheduled recurrences are in addition to the initial execution, so `Effect.repeat(action, Schedule.once)` executes `action` once initially, and if it succeeds, repeats it an additional time.

repeat
(
27
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
.
(method) Pipeable.pipe<Schedule.Schedule<Out, void, never>, Schedule.Schedule<[Out, number], void, never>>(this: Schedule.Schedule<...>, ab: (_: Schedule.Schedule<Out, void, never>) => Schedule.Schedule<...>): Schedule.Schedule<...> (+21 overloads)
pipe
(
import Schedule
Schedule
.
const intersect: <number, unknown, never>(that: Schedule.Schedule<number, unknown, never>) => <Out, In, R>(self: Schedule.Schedule<Out, In, R>) => Schedule.Schedule<[Out, number], In, R> (+1 overload)

Returns a new schedule that performs a geometric intersection on the intervals defined by both schedules.

intersect
(
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(10)))
28
),
29
import Effect
Effect
.
const fork: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>

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
30
)
31
yield*
import TestClock
TestClock
.
const adjust: (durationInput: DurationInput) => Effect.Effect<void>

Accesses a `TestClock` instance in the context and increments the time by the specified duration, running any actions scheduled for on or before the new time in order.

adjust
(
var Infinity: number
Infinity
)
32
yield*
import Fiber
Fiber
.
const join: <[Out, number], never>(self: Fiber.Fiber<[Out, number], never>) => Effect.Effect<[Out, 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<[Out, number], never>
fiber
)
33
}).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Promise<void>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>, bc: (_: Effect.Effect<...>) => Promise<...>): Promise<...> (+21 overloads)
pipe
(
import Effect
Effect
.
const provide: <TestServices, never, never>(layer: Layer<TestServices, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder `R0`

provide
(
import TestContext
TestContext
.
const TestContext: Layer<TestServices, never, never>
TestContext
),
import Effect
Effect
.
const runPromise: <A, E>(effect: Effect.Effect<A, E, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<A>

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

runPromise
)
34
}

The log helper logs the time delay between each execution. We will use this helper to showcase the behavior of various built-in schedules.

Schedules compose in the following primary ways:

  • Union. This performs the union of the intervals of two schedules.
  • Intersection. This performs the intersection of the intervals of two schedules.
  • Sequencing. This concatenates the intervals of one schedule onto another.

Combines two schedules through union, by recurring if either schedule wants to recur, using the minimum of the two delays between recurrences.

1
import {
import Effect
Effect
,
import Schedule
Schedule
,
import TestClock
TestClock
,
import Fiber
Fiber
,
import TestContext
TestContext
} from "effect"
2
30 collapsed lines
3
let
let start: number
start
= 0
4
let
let i: number
i
= 0
5
6
const
const log: <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>) => void
log
= <
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
,
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
>(
7
(parameter) action: Effect.Effect<A, never, never>
action
:
import Effect
Effect
.
interface Effect<out A, out E = never, out R = never> namespace Effect

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`. `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
<
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
>,
8
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
:
import Schedule
Schedule
.
interface Schedule<out Out, in In = unknown, out R = never> namespace Schedule

A `Schedule<Out, In, R>` defines a recurring schedule, which consumes values of type `In`, and which returns values of type `Out`. Schedules are defined as a possibly infinite set of intervals spread out over time. Each interval defines a window in which recurrence is possible. When schedules are used to repeat or retry effects, the starting boundary of each interval produced by a schedule is used as the moment when the effect will be executed again. Schedules compose in the following primary ways: - Union: performs the union of the intervals of two schedules - Intersection: performs the intersection of the intervals of two schedules - Sequence: concatenates the intervals of one schedule onto another In addition, schedule inputs and outputs can be transformed, filtered (to terminate a schedule early in response to some input or output), and so forth. A variety of other operators exist for transforming and combining schedules, and the companion object for `Schedule` contains all common types of schedules, both for performing retrying, as well as performing repetition.

Schedule
<
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, void>
9
) => {
10
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* () {
11
const
const fiber: Fiber.RuntimeFiber<[Out, number], never>
fiber
:
import Fiber
Fiber
.
interface RuntimeFiber<out A, out E = never>

A runtime fiber that is executing an effect. Runtime fibers have an identity and a trace.

RuntimeFiber
<[
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, number]> = yield*
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<A, never, never>> | YieldWrap<Effect.Effect<number, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(
12
function* () {
13
yield*
(parameter) action: Effect.Effect<A, never, never>
action
14
const
const now: number
now
= yield*
import TestClock
TestClock
.
const currentTimeMillis: Effect.Effect<number, never, never>

Accesses the current time of a `TestClock` instance in the context in milliseconds.

currentTimeMillis
15
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
(
16
let i: number
i
=== 0
17
? `delay: ${
const now: number
now
-
let start: number
start
}`
18
:
let i: number
i
=== 10
19
? "..."
20
: `#${
let i: number
i
} delay: ${
const now: number
now
-
let start: number
start
}`
21
)
22
let i: number
i
++
23
let start: number
start
=
const now: number
now
24
}
25
).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<[Out, number], never, never>, Effect.Effect<Fiber.RuntimeFiber<[Out, number], never>, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
26
import Effect
Effect
.
const repeat: <[Out, number], void, never>(schedule: Schedule.Schedule<[Out, number], void, never>) => <E, R>(self: Effect.Effect<void, E, R>) => Effect.Effect<[Out, number], E, R> (+3 overloads)

The `repeat` function returns a new effect that repeats the given effect according to a specified schedule or until the first failure. The scheduled recurrences are in addition to the initial execution, so `Effect.repeat(action, Schedule.once)` executes `action` once initially, and if it succeeds, repeats it an additional time.

repeat
(
27
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
.
(method) Pipeable.pipe<Schedule.Schedule<Out, void, never>, Schedule.Schedule<[Out, number], void, never>>(this: Schedule.Schedule<...>, ab: (_: Schedule.Schedule<Out, void, never>) => Schedule.Schedule<...>): Schedule.Schedule<...> (+21 overloads)
pipe
(
import Schedule
Schedule
.
const intersect: <number, unknown, never>(that: Schedule.Schedule<number, unknown, never>) => <Out, In, R>(self: Schedule.Schedule<Out, In, R>) => Schedule.Schedule<[Out, number], In, R> (+1 overload)

Returns a new schedule that performs a geometric intersection on the intervals defined by both schedules.

intersect
(
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(10)))
28
),
29
import Effect
Effect
.
const fork: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>

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
30
)
31
yield*
import TestClock
TestClock
.
const adjust: (durationInput: DurationInput) => Effect.Effect<void>

Accesses a `TestClock` instance in the context and increments the time by the specified duration, running any actions scheduled for on or before the new time in order.

adjust
(
var Infinity: number
Infinity
)
32
yield*
import Fiber
Fiber
.
const join: <[Out, number], never>(self: Fiber.Fiber<[Out, number], never>) => Effect.Effect<[Out, 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<[Out, number], never>
fiber
)
33
}).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Promise<void>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>, bc: (_: Effect.Effect<...>) => Promise<...>): Promise<...> (+21 overloads)
pipe
(
import Effect
Effect
.
const provide: <TestServices, never, never>(layer: Layer<TestServices, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder `R0`

provide
(
import TestContext
TestContext
.
const TestContext: Layer<TestServices, never, never>
TestContext
),
import Effect
Effect
.
const runPromise: <A, E>(effect: Effect.Effect<A, E, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<A>

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

runPromise
)
34
}
35
36
const
const schedule: Schedule.Schedule<[Duration, number], unknown, never>
schedule
=
import Schedule
Schedule
.
const union: <Duration, unknown, never, number, unknown, never>(self: Schedule.Schedule<Duration, unknown, never>, that: Schedule.Schedule<number, unknown, never>) => Schedule.Schedule<[Duration, number], unknown, never> (+1 overload)

Returns a new schedule that performs a geometric union on the intervals defined by both schedules.

union
(
37
import Schedule
Schedule
.
const exponential: (base: DurationInput, factor?: number) => Schedule.Schedule<Duration>

A schedule that always recurs, but will wait a certain amount between repetitions, given by `base * factor.pow(n)`, where `n` is the number of repetitions so far. Returns the current duration between recurrences.

exponential
("100 millis"),
38
import Schedule
Schedule
.
const spaced: (duration: DurationInput) => Schedule.Schedule<number>

Returns a schedule that recurs continuously, each repetition spaced the specified duration from the last run.

spaced
("1 second")
39
)
40
const
const action: Effect.Effect<void, never, never>
action
=
import Effect
Effect
.
(alias) const void: Effect.Effect<void, never, never> export void
void
41
const log: <void, [Duration, number]>(action: Effect.Effect<void, never, never>, schedule: Schedule.Schedule<[Duration, number], void, never>) => void
log
(
const action: Effect.Effect<void, never, never>
action
,
const schedule: Schedule.Schedule<[Duration, number], unknown, never>
schedule
)
42
/*
43
Output:
44
delay: 0
45
#1 delay: 100 < exponential
46
#2 delay: 200
47
#3 delay: 400
48
#4 delay: 800
49
#5 delay: 1000 < spaced
50
#6 delay: 1000
51
#7 delay: 1000
52
#8 delay: 1000
53
#9 delay: 1000
54
...
55
*/

When we use the combined schedule with Effect.repeat, we observe that the effect is executed repeatedly based on the minimum delay between the two schedules. In this case, the delay alternates between the exponential schedule (increasing delay) and the spaced schedule (constant delay).

Combines two schedules through the intersection, by recurring only if both schedules want to recur, using the maximum of the two delays between recurrences.

1
import {
import Effect
Effect
,
import Schedule
Schedule
,
import TestClock
TestClock
,
import Fiber
Fiber
,
import TestContext
TestContext
} from "effect"
2
30 collapsed lines
3
let
let start: number
start
= 0
4
let
let i: number
i
= 0
5
6
const
const log: <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>) => void
log
= <
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
,
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
>(
7
(parameter) action: Effect.Effect<A, never, never>
action
:
import Effect
Effect
.
interface Effect<out A, out E = never, out R = never> namespace Effect

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`. `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
<
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
>,
8
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
:
import Schedule
Schedule
.
interface Schedule<out Out, in In = unknown, out R = never> namespace Schedule

A `Schedule<Out, In, R>` defines a recurring schedule, which consumes values of type `In`, and which returns values of type `Out`. Schedules are defined as a possibly infinite set of intervals spread out over time. Each interval defines a window in which recurrence is possible. When schedules are used to repeat or retry effects, the starting boundary of each interval produced by a schedule is used as the moment when the effect will be executed again. Schedules compose in the following primary ways: - Union: performs the union of the intervals of two schedules - Intersection: performs the intersection of the intervals of two schedules - Sequence: concatenates the intervals of one schedule onto another In addition, schedule inputs and outputs can be transformed, filtered (to terminate a schedule early in response to some input or output), and so forth. A variety of other operators exist for transforming and combining schedules, and the companion object for `Schedule` contains all common types of schedules, both for performing retrying, as well as performing repetition.

Schedule
<
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, void>
9
) => {
10
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* () {
11
const
const fiber: Fiber.RuntimeFiber<[Out, number], never>
fiber
:
import Fiber
Fiber
.
interface RuntimeFiber<out A, out E = never>

A runtime fiber that is executing an effect. Runtime fibers have an identity and a trace.

RuntimeFiber
<[
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, number]> = yield*
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<A, never, never>> | YieldWrap<Effect.Effect<number, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(
12
function* () {
13
yield*
(parameter) action: Effect.Effect<A, never, never>
action
14
const
const now: number
now
= yield*
import TestClock
TestClock
.
const currentTimeMillis: Effect.Effect<number, never, never>

Accesses the current time of a `TestClock` instance in the context in milliseconds.

currentTimeMillis
15
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
(
16
let i: number
i
=== 0
17
? `delay: ${
const now: number
now
-
let start: number
start
}`
18
:
let i: number
i
=== 10
19
? "..."
20
: `#${
let i: number
i
} delay: ${
const now: number
now
-
let start: number
start
}`
21
)
22
let i: number
i
++
23
let start: number
start
=
const now: number
now
24
}
25
).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<[Out, number], never, never>, Effect.Effect<Fiber.RuntimeFiber<[Out, number], never>, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
26
import Effect
Effect
.
const repeat: <[Out, number], void, never>(schedule: Schedule.Schedule<[Out, number], void, never>) => <E, R>(self: Effect.Effect<void, E, R>) => Effect.Effect<[Out, number], E, R> (+3 overloads)

The `repeat` function returns a new effect that repeats the given effect according to a specified schedule or until the first failure. The scheduled recurrences are in addition to the initial execution, so `Effect.repeat(action, Schedule.once)` executes `action` once initially, and if it succeeds, repeats it an additional time.

repeat
(
27
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
.
(method) Pipeable.pipe<Schedule.Schedule<Out, void, never>, Schedule.Schedule<[Out, number], void, never>>(this: Schedule.Schedule<...>, ab: (_: Schedule.Schedule<Out, void, never>) => Schedule.Schedule<...>): Schedule.Schedule<...> (+21 overloads)
pipe
(
import Schedule
Schedule
.
const intersect: <number, unknown, never>(that: Schedule.Schedule<number, unknown, never>) => <Out, In, R>(self: Schedule.Schedule<Out, In, R>) => Schedule.Schedule<[Out, number], In, R> (+1 overload)

Returns a new schedule that performs a geometric intersection on the intervals defined by both schedules.

intersect
(
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(10)))
28
),
29
import Effect
Effect
.
const fork: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>

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
30
)
31
yield*
import TestClock
TestClock
.
const adjust: (durationInput: DurationInput) => Effect.Effect<void>

Accesses a `TestClock` instance in the context and increments the time by the specified duration, running any actions scheduled for on or before the new time in order.

adjust
(
var Infinity: number
Infinity
)
32
yield*
import Fiber
Fiber
.
const join: <[Out, number], never>(self: Fiber.Fiber<[Out, number], never>) => Effect.Effect<[Out, 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<[Out, number], never>
fiber
)
33
}).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Promise<void>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>, bc: (_: Effect.Effect<...>) => Promise<...>): Promise<...> (+21 overloads)
pipe
(
import Effect
Effect
.
const provide: <TestServices, never, never>(layer: Layer<TestServices, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder `R0`

provide
(
import TestContext
TestContext
.
const TestContext: Layer<TestServices, never, never>
TestContext
),
import Effect
Effect
.
const runPromise: <A, E>(effect: Effect.Effect<A, E, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<A>

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

runPromise
)
34
}
35
36
const
const schedule: Schedule.Schedule<[Duration, number], unknown, never>
schedule
=
import Schedule
Schedule
.
const intersect: <Duration, unknown, never, number, unknown, never>(self: Schedule.Schedule<Duration, unknown, never>, that: Schedule.Schedule<number, unknown, never>) => Schedule.Schedule<[Duration, number], unknown, never> (+1 overload)

Returns a new schedule that performs a geometric intersection on the intervals defined by both schedules.

intersect
(
37
import Schedule
Schedule
.
const exponential: (base: DurationInput, factor?: number) => Schedule.Schedule<Duration>

A schedule that always recurs, but will wait a certain amount between repetitions, given by `base * factor.pow(n)`, where `n` is the number of repetitions so far. Returns the current duration between recurrences.

exponential
("10 millis"),
38
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(5)
39
)
40
const
const action: Effect.Effect<void, never, never>
action
=
import Effect
Effect
.
(alias) const void: Effect.Effect<void, never, never> export void
void
41
const log: <void, [Duration, number]>(action: Effect.Effect<void, never, never>, schedule: Schedule.Schedule<[Duration, number], void, never>) => void
log
(
const action: Effect.Effect<void, never, never>
action
,
const schedule: Schedule.Schedule<[Duration, number], unknown, never>
schedule
)
42
/*
43
Output:
44
delay: 0
45
#1 delay: 10 < exponential
46
#2 delay: 20
47
#3 delay: 40
48
#4 delay: 80
49
#5 delay: 160
50
(end) < recurs
51
*/

When we use the combined schedule with Effect.repeat, we observe that the effect is executed repeatedly only if both schedules want it to recur. The delay between recurrences is determined by the maximum delay between the two schedules. In this case, the delay follows the progression of the exponential schedule until the maximum number of recurrences specified by the recursive schedule is reached.

Combines two schedules sequentially, by following the first policy until it ends, and then following the second policy.

1
import {
import Effect
Effect
,
import Schedule
Schedule
,
import TestClock
TestClock
,
import Fiber
Fiber
,
import TestContext
TestContext
} from "effect"
2
30 collapsed lines
3
let
let start: number
start
= 0
4
let
let i: number
i
= 0
5
6
const
const log: <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>) => void
log
= <
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
,
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
>(
7
(parameter) action: Effect.Effect<A, never, never>
action
:
import Effect
Effect
.
interface Effect<out A, out E = never, out R = never> namespace Effect

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`. `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
<
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
>,
8
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
:
import Schedule
Schedule
.
interface Schedule<out Out, in In = unknown, out R = never> namespace Schedule

A `Schedule<Out, In, R>` defines a recurring schedule, which consumes values of type `In`, and which returns values of type `Out`. Schedules are defined as a possibly infinite set of intervals spread out over time. Each interval defines a window in which recurrence is possible. When schedules are used to repeat or retry effects, the starting boundary of each interval produced by a schedule is used as the moment when the effect will be executed again. Schedules compose in the following primary ways: - Union: performs the union of the intervals of two schedules - Intersection: performs the intersection of the intervals of two schedules - Sequence: concatenates the intervals of one schedule onto another In addition, schedule inputs and outputs can be transformed, filtered (to terminate a schedule early in response to some input or output), and so forth. A variety of other operators exist for transforming and combining schedules, and the companion object for `Schedule` contains all common types of schedules, both for performing retrying, as well as performing repetition.

Schedule
<
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, void>
9
) => {
10
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* () {
11
const
const fiber: Fiber.RuntimeFiber<[Out, number], never>
fiber
:
import Fiber
Fiber
.
interface RuntimeFiber<out A, out E = never>

A runtime fiber that is executing an effect. Runtime fibers have an identity and a trace.

RuntimeFiber
<[
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, number]> = yield*
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<A, never, never>> | YieldWrap<Effect.Effect<number, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(
12
function* () {
13
yield*
(parameter) action: Effect.Effect<A, never, never>
action
14
const
const now: number
now
= yield*
import TestClock
TestClock
.
const currentTimeMillis: Effect.Effect<number, never, never>

Accesses the current time of a `TestClock` instance in the context in milliseconds.

currentTimeMillis
15
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
(
16
let i: number
i
=== 0
17
? `delay: ${
const now: number
now
-
let start: number
start
}`
18
:
let i: number
i
=== 10
19
? "..."
20
: `#${
let i: number
i
} delay: ${
const now: number
now
-
let start: number
start
}`
21
)
22
let i: number
i
++
23
let start: number
start
=
const now: number
now
24
}
25
).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<[Out, number], never, never>, Effect.Effect<Fiber.RuntimeFiber<[Out, number], never>, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
26
import Effect
Effect
.
const repeat: <[Out, number], void, never>(schedule: Schedule.Schedule<[Out, number], void, never>) => <E, R>(self: Effect.Effect<void, E, R>) => Effect.Effect<[Out, number], E, R> (+3 overloads)

The `repeat` function returns a new effect that repeats the given effect according to a specified schedule or until the first failure. The scheduled recurrences are in addition to the initial execution, so `Effect.repeat(action, Schedule.once)` executes `action` once initially, and if it succeeds, repeats it an additional time.

repeat
(
27
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
.
(method) Pipeable.pipe<Schedule.Schedule<Out, void, never>, Schedule.Schedule<[Out, number], void, never>>(this: Schedule.Schedule<...>, ab: (_: Schedule.Schedule<Out, void, never>) => Schedule.Schedule<...>): Schedule.Schedule<...> (+21 overloads)
pipe
(
import Schedule
Schedule
.
const intersect: <number, unknown, never>(that: Schedule.Schedule<number, unknown, never>) => <Out, In, R>(self: Schedule.Schedule<Out, In, R>) => Schedule.Schedule<[Out, number], In, R> (+1 overload)

Returns a new schedule that performs a geometric intersection on the intervals defined by both schedules.

intersect
(
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(10)))
28
),
29
import Effect
Effect
.
const fork: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>

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
30
)
31
yield*
import TestClock
TestClock
.
const adjust: (durationInput: DurationInput) => Effect.Effect<void>

Accesses a `TestClock` instance in the context and increments the time by the specified duration, running any actions scheduled for on or before the new time in order.

adjust
(
var Infinity: number
Infinity
)
32
yield*
import Fiber
Fiber
.
const join: <[Out, number], never>(self: Fiber.Fiber<[Out, number], never>) => Effect.Effect<[Out, 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<[Out, number], never>
fiber
)
33
}).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Promise<void>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>, bc: (_: Effect.Effect<...>) => Promise<...>): Promise<...> (+21 overloads)
pipe
(
import Effect
Effect
.
const provide: <TestServices, never, never>(layer: Layer<TestServices, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder `R0`

provide
(
import TestContext
TestContext
.
const TestContext: Layer<TestServices, never, never>
TestContext
),
import Effect
Effect
.
const runPromise: <A, E>(effect: Effect.Effect<A, E, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<A>

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

runPromise
)
34
}
35
36
const
const schedule: Schedule.Schedule<number, unknown, never>
schedule
=
import Schedule
Schedule
.
const andThen: <number, unknown, never, number, unknown, never>(self: Schedule.Schedule<number, unknown, never>, that: Schedule.Schedule<number, unknown, never>) => Schedule.Schedule<number, unknown, never> (+1 overload)

The same as `andThenEither`, but merges the output.

andThen
(
37
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(5),
38
import Schedule
Schedule
.
const spaced: (duration: DurationInput) => Schedule.Schedule<number>

Returns a schedule that recurs continuously, each repetition spaced the specified duration from the last run.

spaced
("1 second")
39
)
40
const
const action: Effect.Effect<void, never, never>
action
=
import Effect
Effect
.
(alias) const void: Effect.Effect<void, never, never> export void
void
41
const log: <void, number>(action: Effect.Effect<void, never, never>, schedule: Schedule.Schedule<number, void, never>) => void
log
(
const action: Effect.Effect<void, never, never>
action
,
const schedule: Schedule.Schedule<number, unknown, never>
schedule
)
42
/*
43
Output:
44
delay: 0
45
#1 delay: 0 < recurs
46
#2 delay: 0
47
#3 delay: 0
48
#4 delay: 0
49
#5 delay: 0
50
#6 delay: 1000 < spaced
51
#7 delay: 1000
52
#8 delay: 1000
53
#9 delay: 1000
54
...
55
*/

When we use the combined schedule with Effect.repeat, we observe that the effect follows the policy of the first schedule (recurs) until it completes the specified number of recurrences. After that, it switches to the policy of the second schedule (spaced) and continues repeating the effect with the fixed delay between recurrences.

A jittered is a combinator that takes one schedule and returns another schedule of the same type except for the delay which is applied randomly

When a resource is out of service due to overload or contention, retrying and backing off doesn’t help us. If all failed API calls are backed off to the same point of time, they cause another overload or contention. Jitter adds some amount of randomness to the delay of the schedule. This helps us to avoid ending up accidentally synchronizing and taking the service down by accident.

Research shows that Schedule.jittered(0.0, 1.0) is very suitable for retrying.

1
import {
import Effect
Effect
,
import Schedule
Schedule
,
import TestClock
TestClock
,
import Fiber
Fiber
,
import TestContext
TestContext
} from "effect"
2
30 collapsed lines
3
let
let start: number
start
= 0
4
let
let i: number
i
= 0
5
6
const
const log: <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>) => void
log
= <
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
,
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
>(
7
(parameter) action: Effect.Effect<A, never, never>
action
:
import Effect
Effect
.
interface Effect<out A, out E = never, out R = never> namespace Effect

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`. `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
<
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
>,
8
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
:
import Schedule
Schedule
.
interface Schedule<out Out, in In = unknown, out R = never> namespace Schedule

A `Schedule<Out, In, R>` defines a recurring schedule, which consumes values of type `In`, and which returns values of type `Out`. Schedules are defined as a possibly infinite set of intervals spread out over time. Each interval defines a window in which recurrence is possible. When schedules are used to repeat or retry effects, the starting boundary of each interval produced by a schedule is used as the moment when the effect will be executed again. Schedules compose in the following primary ways: - Union: performs the union of the intervals of two schedules - Intersection: performs the intersection of the intervals of two schedules - Sequence: concatenates the intervals of one schedule onto another In addition, schedule inputs and outputs can be transformed, filtered (to terminate a schedule early in response to some input or output), and so forth. A variety of other operators exist for transforming and combining schedules, and the companion object for `Schedule` contains all common types of schedules, both for performing retrying, as well as performing repetition.

Schedule
<
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, void>
9
) => {
10
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* () {
11
const
const fiber: Fiber.RuntimeFiber<[Out, number], never>
fiber
:
import Fiber
Fiber
.
interface RuntimeFiber<out A, out E = never>

A runtime fiber that is executing an effect. Runtime fibers have an identity and a trace.

RuntimeFiber
<[
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, number]> = yield*
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<A, never, never>> | YieldWrap<Effect.Effect<number, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(
12
function* () {
13
yield*
(parameter) action: Effect.Effect<A, never, never>
action
14
const
const now: number
now
= yield*
import TestClock
TestClock
.
const currentTimeMillis: Effect.Effect<number, never, never>

Accesses the current time of a `TestClock` instance in the context in milliseconds.

currentTimeMillis
15
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
(
16
let i: number
i
=== 0
17
? `delay: ${
const now: number
now
-
let start: number
start
}`
18
:
let i: number
i
=== 10
19
? "..."
20
: `#${
let i: number
i
} delay: ${
const now: number
now
-
let start: number
start
}`
21
)
22
let i: number
i
++
23
let start: number
start
=
const now: number
now
24
}
25
).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<[Out, number], never, never>, Effect.Effect<Fiber.RuntimeFiber<[Out, number], never>, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
26
import Effect
Effect
.
const repeat: <[Out, number], void, never>(schedule: Schedule.Schedule<[Out, number], void, never>) => <E, R>(self: Effect.Effect<void, E, R>) => Effect.Effect<[Out, number], E, R> (+3 overloads)

The `repeat` function returns a new effect that repeats the given effect according to a specified schedule or until the first failure. The scheduled recurrences are in addition to the initial execution, so `Effect.repeat(action, Schedule.once)` executes `action` once initially, and if it succeeds, repeats it an additional time.

repeat
(
27
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
.
(method) Pipeable.pipe<Schedule.Schedule<Out, void, never>, Schedule.Schedule<[Out, number], void, never>>(this: Schedule.Schedule<...>, ab: (_: Schedule.Schedule<Out, void, never>) => Schedule.Schedule<...>): Schedule.Schedule<...> (+21 overloads)
pipe
(
import Schedule
Schedule
.
const intersect: <number, unknown, never>(that: Schedule.Schedule<number, unknown, never>) => <Out, In, R>(self: Schedule.Schedule<Out, In, R>) => Schedule.Schedule<[Out, number], In, R> (+1 overload)

Returns a new schedule that performs a geometric intersection on the intervals defined by both schedules.

intersect
(
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(10)))
28
),
29
import Effect
Effect
.
const fork: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>

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
30
)
31
yield*
import TestClock
TestClock
.
const adjust: (durationInput: DurationInput) => Effect.Effect<void>

Accesses a `TestClock` instance in the context and increments the time by the specified duration, running any actions scheduled for on or before the new time in order.

adjust
(
var Infinity: number
Infinity
)
32
yield*
import Fiber
Fiber
.
const join: <[Out, number], never>(self: Fiber.Fiber<[Out, number], never>) => Effect.Effect<[Out, 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<[Out, number], never>
fiber
)
33
}).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Promise<void>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>, bc: (_: Effect.Effect<...>) => Promise<...>): Promise<...> (+21 overloads)
pipe
(
import Effect
Effect
.
const provide: <TestServices, never, never>(layer: Layer<TestServices, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder `R0`

provide
(
import TestContext
TestContext
.
const TestContext: Layer<TestServices, never, never>
TestContext
),
import Effect
Effect
.
const runPromise: <A, E>(effect: Effect.Effect<A, E, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<A>

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

runPromise
)
34
}
35
36
const
const schedule: Schedule.Schedule<Duration, unknown, never>
schedule
=
import Schedule
Schedule
.
const jittered: <Duration, unknown, never>(self: Schedule.Schedule<Duration, unknown, never>) => Schedule.Schedule<Duration, unknown, never>

Returns a new schedule that randomly modifies the size of the intervals of this schedule. Defaults `min` to `0.8` and `max` to `1.2`. The new interval size is between `min * old interval size` and `max * old interval size`.

jittered
(
import Schedule
Schedule
.
const exponential: (base: DurationInput, factor?: number) => Schedule.Schedule<Duration>

A schedule that always recurs, but will wait a certain amount between repetitions, given by `base * factor.pow(n)`, where `n` is the number of repetitions so far. Returns the current duration between recurrences.

exponential
("10 millis"))
37
const
const action: Effect.Effect<void, never, never>
action
=
import Effect
Effect
.
(alias) const void: Effect.Effect<void, never, never> export void
void
38
const log: <void, Duration>(action: Effect.Effect<void, never, never>, schedule: Schedule.Schedule<Duration, void, never>) => void
log
(
const action: Effect.Effect<void, never, never>
action
,
const schedule: Schedule.Schedule<Duration, unknown, never>
schedule
)
39
/*
40
Output:
41
delay: 0
42
#1 delay: 9.006765
43
#2 delay: 20.549507999999996
44
#3 delay: 45.86659000000001
45
#4 delay: 77.055037
46
#5 delay: 178.06722299999998
47
#6 delay: 376.056965
48
#7 delay: 728.732785
49
#8 delay: 1178.174953
50
#9 delay: 2331.4659370000004
51
...
52
*/

In this example, we use the jittered combinator to apply jitter to an exponential schedule. The exponential schedule increases the delay between each repetition exponentially. By adding jitter to the schedule, the delays become randomly adjusted within a certain range.

We can filter inputs or outputs of a schedule with whileInput and whileOutput.

1
import {
import Effect
Effect
,
import Schedule
Schedule
,
import TestClock
TestClock
,
import Fiber
Fiber
,
import TestContext
TestContext
} from "effect"
2
30 collapsed lines
3
let
let start: number
start
= 0
4
let
let i: number
i
= 0
5
6
const
const log: <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>) => void
log
= <
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
,
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
>(
7
(parameter) action: Effect.Effect<A, never, never>
action
:
import Effect
Effect
.
interface Effect<out A, out E = never, out R = never> namespace Effect

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`. `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
<
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
>,
8
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
:
import Schedule
Schedule
.
interface Schedule<out Out, in In = unknown, out R = never> namespace Schedule

A `Schedule<Out, In, R>` defines a recurring schedule, which consumes values of type `In`, and which returns values of type `Out`. Schedules are defined as a possibly infinite set of intervals spread out over time. Each interval defines a window in which recurrence is possible. When schedules are used to repeat or retry effects, the starting boundary of each interval produced by a schedule is used as the moment when the effect will be executed again. Schedules compose in the following primary ways: - Union: performs the union of the intervals of two schedules - Intersection: performs the intersection of the intervals of two schedules - Sequence: concatenates the intervals of one schedule onto another In addition, schedule inputs and outputs can be transformed, filtered (to terminate a schedule early in response to some input or output), and so forth. A variety of other operators exist for transforming and combining schedules, and the companion object for `Schedule` contains all common types of schedules, both for performing retrying, as well as performing repetition.

Schedule
<
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, void>
9
) => {
10
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* () {
11
const
const fiber: Fiber.RuntimeFiber<[Out, number], never>
fiber
:
import Fiber
Fiber
.
interface RuntimeFiber<out A, out E = never>

A runtime fiber that is executing an effect. Runtime fibers have an identity and a trace.

RuntimeFiber
<[
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, number]> = yield*
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<A, never, never>> | YieldWrap<Effect.Effect<number, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(
12
function* () {
13
yield*
(parameter) action: Effect.Effect<A, never, never>
action
14
const
const now: number
now
= yield*
import TestClock
TestClock
.
const currentTimeMillis: Effect.Effect<number, never, never>

Accesses the current time of a `TestClock` instance in the context in milliseconds.

currentTimeMillis
15
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
(
16
let i: number
i
=== 0
17
? `delay: ${
const now: number
now
-
let start: number
start
}`
18
:
let i: number
i
=== 10
19
? "..."
20
: `#${
let i: number
i
} delay: ${
const now: number
now
-
let start: number
start
}`
21
)
22
let i: number
i
++
23
let start: number
start
=
const now: number
now
24
}
25
).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<[Out, number], never, never>, Effect.Effect<Fiber.RuntimeFiber<[Out, number], never>, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
26
import Effect
Effect
.
const repeat: <[Out, number], void, never>(schedule: Schedule.Schedule<[Out, number], void, never>) => <E, R>(self: Effect.Effect<void, E, R>) => Effect.Effect<[Out, number], E, R> (+3 overloads)

The `repeat` function returns a new effect that repeats the given effect according to a specified schedule or until the first failure. The scheduled recurrences are in addition to the initial execution, so `Effect.repeat(action, Schedule.once)` executes `action` once initially, and if it succeeds, repeats it an additional time.

repeat
(
27
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
.
(method) Pipeable.pipe<Schedule.Schedule<Out, void, never>, Schedule.Schedule<[Out, number], void, never>>(this: Schedule.Schedule<...>, ab: (_: Schedule.Schedule<Out, void, never>) => Schedule.Schedule<...>): Schedule.Schedule<...> (+21 overloads)
pipe
(
import Schedule
Schedule
.
const intersect: <number, unknown, never>(that: Schedule.Schedule<number, unknown, never>) => <Out, In, R>(self: Schedule.Schedule<Out, In, R>) => Schedule.Schedule<[Out, number], In, R> (+1 overload)

Returns a new schedule that performs a geometric intersection on the intervals defined by both schedules.

intersect
(
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(10)))
28
),
29
import Effect
Effect
.
const fork: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>

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
30
)
31
yield*
import TestClock
TestClock
.
const adjust: (durationInput: DurationInput) => Effect.Effect<void>

Accesses a `TestClock` instance in the context and increments the time by the specified duration, running any actions scheduled for on or before the new time in order.

adjust
(
var Infinity: number
Infinity
)
32
yield*
import Fiber
Fiber
.
const join: <[Out, number], never>(self: Fiber.Fiber<[Out, number], never>) => Effect.Effect<[Out, 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<[Out, number], never>
fiber
)
33
}).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Promise<void>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>, bc: (_: Effect.Effect<...>) => Promise<...>): Promise<...> (+21 overloads)
pipe
(
import Effect
Effect
.
const provide: <TestServices, never, never>(layer: Layer<TestServices, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder `R0`

provide
(
import TestContext
TestContext
.
const TestContext: Layer<TestServices, never, never>
TestContext
),
import Effect
Effect
.
const runPromise: <A, E>(effect: Effect.Effect<A, E, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<A>

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

runPromise
)
34
}
35
36
const
const schedule: Schedule.Schedule<number, unknown, never>
schedule
=
import Schedule
Schedule
.
const whileOutput: <number, unknown, never>(self: Schedule.Schedule<number, unknown, never>, f: Predicate<number>) => Schedule.Schedule<number, unknown, never> (+1 overload)

Returns a new schedule that continues for as long the specified predicate on the output evaluates to true.

whileOutput
(
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(5), (
(parameter) n: number
n
) =>
(parameter) n: number
n
<= 2)
37
const
const action: Effect.Effect<void, never, never>
action
=
import Effect
Effect
.
(alias) const void: Effect.Effect<void, never, never> export void
void
38
const log: <void, number>(action: Effect.Effect<void, never, never>, schedule: Schedule.Schedule<number, void, never>) => void
log
(
const action: Effect.Effect<void, never, never>
action
,
const schedule: Schedule.Schedule<number, unknown, never>
schedule
)
39
/*
40
Output:
41
delay: 0
42
#1 delay: 0 < recurs
43
#2 delay: 0
44
#3 delay: 0
45
(end) < whileOutput
46
*/

In this example, we create a schedule using Schedule.recurs(5) to repeat a certain action up to 5 times. However, we apply the whileOutput combinator with a predicate that filters out outputs greater than 2. As a result, the schedule stops producing outputs once the value exceeds 2, and the repetition ends.

Modifies the delay of a schedule.

1
import {
import Effect
Effect
,
import Schedule
Schedule
,
import TestClock
TestClock
,
import Fiber
Fiber
,
import TestContext
TestContext
} from "effect"
2
30 collapsed lines
3
let
let start: number
start
= 0
4
let
let i: number
i
= 0
5
6
const
const log: <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>) => void
log
= <
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
,
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
>(
7
(parameter) action: Effect.Effect<A, never, never>
action
:
import Effect
Effect
.
interface Effect<out A, out E = never, out R = never> namespace Effect

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`. `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
<
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
>,
8
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
:
import Schedule
Schedule
.
interface Schedule<out Out, in In = unknown, out R = never> namespace Schedule

A `Schedule<Out, In, R>` defines a recurring schedule, which consumes values of type `In`, and which returns values of type `Out`. Schedules are defined as a possibly infinite set of intervals spread out over time. Each interval defines a window in which recurrence is possible. When schedules are used to repeat or retry effects, the starting boundary of each interval produced by a schedule is used as the moment when the effect will be executed again. Schedules compose in the following primary ways: - Union: performs the union of the intervals of two schedules - Intersection: performs the intersection of the intervals of two schedules - Sequence: concatenates the intervals of one schedule onto another In addition, schedule inputs and outputs can be transformed, filtered (to terminate a schedule early in response to some input or output), and so forth. A variety of other operators exist for transforming and combining schedules, and the companion object for `Schedule` contains all common types of schedules, both for performing retrying, as well as performing repetition.

Schedule
<
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, void>
9
) => {
10
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* () {
11
const
const fiber: Fiber.RuntimeFiber<[Out, number], never>
fiber
:
import Fiber
Fiber
.
interface RuntimeFiber<out A, out E = never>

A runtime fiber that is executing an effect. Runtime fibers have an identity and a trace.

RuntimeFiber
<[
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, number]> = yield*
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<A, never, never>> | YieldWrap<Effect.Effect<number, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(
12
function* () {
13
yield*
(parameter) action: Effect.Effect<A, never, never>
action
14
const
const now: number
now
= yield*
import TestClock
TestClock
.
const currentTimeMillis: Effect.Effect<number, never, never>

Accesses the current time of a `TestClock` instance in the context in milliseconds.

currentTimeMillis
15
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
(
16
let i: number
i
=== 0
17
? `delay: ${
const now: number
now
-
let start: number
start
}`
18
:
let i: number
i
=== 10
19
? "..."
20
: `#${
let i: number
i
} delay: ${
const now: number
now
-
let start: number
start
}`
21
)
22
let i: number
i
++
23
let start: number
start
=
const now: number
now
24
}
25
).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<[Out, number], never, never>, Effect.Effect<Fiber.RuntimeFiber<[Out, number], never>, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
26
import Effect
Effect
.
const repeat: <[Out, number], void, never>(schedule: Schedule.Schedule<[Out, number], void, never>) => <E, R>(self: Effect.Effect<void, E, R>) => Effect.Effect<[Out, number], E, R> (+3 overloads)

The `repeat` function returns a new effect that repeats the given effect according to a specified schedule or until the first failure. The scheduled recurrences are in addition to the initial execution, so `Effect.repeat(action, Schedule.once)` executes `action` once initially, and if it succeeds, repeats it an additional time.

repeat
(
27
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
.
(method) Pipeable.pipe<Schedule.Schedule<Out, void, never>, Schedule.Schedule<[Out, number], void, never>>(this: Schedule.Schedule<...>, ab: (_: Schedule.Schedule<Out, void, never>) => Schedule.Schedule<...>): Schedule.Schedule<...> (+21 overloads)
pipe
(
import Schedule
Schedule
.
const intersect: <number, unknown, never>(that: Schedule.Schedule<number, unknown, never>) => <Out, In, R>(self: Schedule.Schedule<Out, In, R>) => Schedule.Schedule<[Out, number], In, R> (+1 overload)

Returns a new schedule that performs a geometric intersection on the intervals defined by both schedules.

intersect
(
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(10)))
28
),
29
import Effect
Effect
.
const fork: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>

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
30
)
31
yield*
import TestClock
TestClock
.
const adjust: (durationInput: DurationInput) => Effect.Effect<void>

Accesses a `TestClock` instance in the context and increments the time by the specified duration, running any actions scheduled for on or before the new time in order.

adjust
(
var Infinity: number
Infinity
)
32
yield*
import Fiber
Fiber
.
const join: <[Out, number], never>(self: Fiber.Fiber<[Out, number], never>) => Effect.Effect<[Out, 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<[Out, number], never>
fiber
)
33
}).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Promise<void>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>, bc: (_: Effect.Effect<...>) => Promise<...>): Promise<...> (+21 overloads)
pipe
(
import Effect
Effect
.
const provide: <TestServices, never, never>(layer: Layer<TestServices, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder `R0`

provide
(
import TestContext
TestContext
.
const TestContext: Layer<TestServices, never, never>
TestContext
),
import Effect
Effect
.
const runPromise: <A, E>(effect: Effect.Effect<A, E, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<A>

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

runPromise
)
34
}
35
36
const
const schedule: Schedule.Schedule<number, unknown, never>
schedule
=
import Schedule
Schedule
.
const modifyDelay: <number, unknown, never>(self: Schedule.Schedule<number, unknown, never>, f: (out: number, duration: Duration) => DurationInput) => Schedule.Schedule<...> (+1 overload)

Returns a new schedule that modifies the delay using the specified function.

modifyDelay
(
37
import Schedule
Schedule
.
const spaced: (duration: DurationInput) => Schedule.Schedule<number>

Returns a schedule that recurs continuously, each repetition spaced the specified duration from the last run.

spaced
("1 second"),
38
(
(parameter) _: number
_
) => "100 millis"
39
)
40
const
const action: Effect.Effect<void, never, never>
action
=
import Effect
Effect
.
(alias) const void: Effect.Effect<void, never, never> export void
void
41
const log: <void, number>(action: Effect.Effect<void, never, never>, schedule: Schedule.Schedule<number, void, never>) => void
log
(
const action: Effect.Effect<void, never, never>
action
,
const schedule: Schedule.Schedule<number, unknown, never>
schedule
)
42
/*
43
Output:
44
delay: 0
45
#1 delay: 100 < modifyDelay
46
#2 delay: 100
47
#3 delay: 100
48
#4 delay: 100
49
#5 delay: 100
50
#6 delay: 100
51
#7 delay: 100
52
#8 delay: 100
53
#9 delay: 100
54
...
55
*/

Whenever we need to effectfully process each schedule input/output, we can use tapInput and tapOutput.

We can use these two functions for logging purposes:

1
import {
2
import Effect
Effect
,
3
import Schedule
Schedule
,
4
import TestClock
TestClock
,
5
import Fiber
Fiber
,
6
import TestContext
TestContext
,
7
import Console
Console
8
} from "effect"
9
30 collapsed lines
10
let
let start: number
start
= 0
11
let
let i: number
i
= 0
12
13
const
const log: <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>) => void
log
= <
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
,
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
>(
14
(parameter) action: Effect.Effect<A, never, never>
action
:
import Effect
Effect
.
interface Effect<out A, out E = never, out R = never> namespace Effect

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`. `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
<
(type parameter) A in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
A
>,
15
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
:
import Schedule
Schedule
.
interface Schedule<out Out, in In = unknown, out R = never> namespace Schedule

A `Schedule<Out, In, R>` defines a recurring schedule, which consumes values of type `In`, and which returns values of type `Out`. Schedules are defined as a possibly infinite set of intervals spread out over time. Each interval defines a window in which recurrence is possible. When schedules are used to repeat or retry effects, the starting boundary of each interval produced by a schedule is used as the moment when the effect will be executed again. Schedules compose in the following primary ways: - Union: performs the union of the intervals of two schedules - Intersection: performs the intersection of the intervals of two schedules - Sequence: concatenates the intervals of one schedule onto another In addition, schedule inputs and outputs can be transformed, filtered (to terminate a schedule early in response to some input or output), and so forth. A variety of other operators exist for transforming and combining schedules, and the companion object for `Schedule` contains all common types of schedules, both for performing retrying, as well as performing repetition.

Schedule
<
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, void>
16
) => {
17
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* () {
18
const
const fiber: Fiber.RuntimeFiber<[Out, number], never>
fiber
:
import Fiber
Fiber
.
interface RuntimeFiber<out A, out E = never>

A runtime fiber that is executing an effect. Runtime fibers have an identity and a trace.

RuntimeFiber
<[
(type parameter) Out in <A, Out>(action: Effect.Effect<A>, schedule: Schedule.Schedule<Out, void>): void
Out
, number]> = yield*
import Effect
Effect
.
const gen: <YieldWrap<Effect.Effect<A, never, never>> | YieldWrap<Effect.Effect<number, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)
gen
(
19
function* () {
20
yield*
(parameter) action: Effect.Effect<A, never, never>
action
21
const
const now: number
now
= yield*
import TestClock
TestClock
.
const currentTimeMillis: Effect.Effect<number, never, never>

Accesses the current time of a `TestClock` instance in the context in milliseconds.

currentTimeMillis
22
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) globalThis.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
(
23
let i: number
i
=== 0
24
? `delay: ${
const now: number
now
-
let start: number
start
}`
25
:
let i: number
i
=== 10
26
? "..."
27
: `#${
let i: number
i
} delay: ${
const now: number
now
-
let start: number
start
}`
28
)
29
let i: number
i
++
30
let start: number
start
=
const now: number
now
31
}
32
).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<[Out, number], never, never>, Effect.Effect<Fiber.RuntimeFiber<[Out, number], never>, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
33
import Effect
Effect
.
const repeat: <[Out, number], void, never>(schedule: Schedule.Schedule<[Out, number], void, never>) => <E, R>(self: Effect.Effect<void, E, R>) => Effect.Effect<[Out, number], E, R> (+3 overloads)

The `repeat` function returns a new effect that repeats the given effect according to a specified schedule or until the first failure. The scheduled recurrences are in addition to the initial execution, so `Effect.repeat(action, Schedule.once)` executes `action` once initially, and if it succeeds, repeats it an additional time.

repeat
(
34
(parameter) schedule: Schedule.Schedule<Out, void, never>
schedule
.
(method) Pipeable.pipe<Schedule.Schedule<Out, void, never>, Schedule.Schedule<[Out, number], void, never>>(this: Schedule.Schedule<...>, ab: (_: Schedule.Schedule<Out, void, never>) => Schedule.Schedule<...>): Schedule.Schedule<...> (+21 overloads)
pipe
(
import Schedule
Schedule
.
const intersect: <number, unknown, never>(that: Schedule.Schedule<number, unknown, never>) => <Out, In, R>(self: Schedule.Schedule<Out, In, R>) => Schedule.Schedule<[Out, number], In, R> (+1 overload)

Returns a new schedule that performs a geometric intersection on the intervals defined by both schedules.

intersect
(
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(10)))
35
),
36
import Effect
Effect
.
const fork: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>

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
37
)
38
yield*
import TestClock
TestClock
.
const adjust: (durationInput: DurationInput) => Effect.Effect<void>

Accesses a `TestClock` instance in the context and increments the time by the specified duration, running any actions scheduled for on or before the new time in order.

adjust
(
var Infinity: number
Infinity
)
39
yield*
import Fiber
Fiber
.
const join: <[Out, number], never>(self: Fiber.Fiber<[Out, number], never>) => Effect.Effect<[Out, 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<[Out, number], never>
fiber
)
40
}).
(method) Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Promise<void>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>, bc: (_: Effect.Effect<...>) => Promise<...>): Promise<...> (+21 overloads)
pipe
(
import Effect
Effect
.
const provide: <TestServices, never, never>(layer: Layer<TestServices, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder `R0`

provide
(
import TestContext
TestContext
.
const TestContext: Layer<TestServices, never, never>
TestContext
),
import Effect
Effect
.
const runPromise: <A, E>(effect: Effect.Effect<A, E, never>, options?: { readonly signal?: AbortSignal; } | undefined) => Promise<A>

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

runPromise
)
41
}
42
43
const
const schedule: Schedule.Schedule<number, unknown, never>
schedule
=
import Schedule
Schedule
.
const tapOutput: <number, unknown, never, number, void, never>(self: Schedule.Schedule<number, unknown, never>, f: (out: number) => Effect.Effect<void, never, never>) => Schedule.Schedule<number, unknown, never> (+1 overload)

Returns a new schedule that effectfully processes every output from this schedule.

tapOutput
(
import Schedule
Schedule
.
const recurs: (n: number) => Schedule.Schedule<number>

A schedule spanning all time, which can be stepped only the specified number of times before it terminates.

recurs
(2), (
(parameter) n: number
n
) =>
44
import Console
Console
.
const log: (...args: ReadonlyArray<any>) => Effect.Effect<void>
log
(`repeating ${
(parameter) n: number
n
}`)
45
)
46
const
const action: Effect.Effect<void, never, never>
action
=
import Effect
Effect
.
(alias) const void: Effect.Effect<void, never, never> export void
void
47
const log: <void, number>(action: Effect.Effect<void, never, never>, schedule: Schedule.Schedule<number, void, never>) => void
log
(
const action: Effect.Effect<void, never, never>
action
,
const schedule: Schedule.Schedule<number, unknown, never>
schedule
)
48
/*
49
Output:
50
delay: 0
51
repeating 0
52
#1 delay: 0
53
repeating 1
54
#2 delay: 0
55
repeating 2
56
*/