Skip to content

Built-In 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.

A schedule that always recurs and produces number of recurrence at each run.

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 forever: Schedule.Schedule<number, unknown, never>

A schedule that always recurs, producing a count of repeats: 0, 1, 2.

forever
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 < forever
43
#2 delay: 0
44
#3 delay: 0
45
#4 delay: 0
46
#5 delay: 0
47
#6 delay: 0
48
#7 delay: 0
49
#8 delay: 0
50
#9 delay: 0
51
...
52
*/

A schedule that recurs one time.

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<void, unknown, never>
schedule
=
import Schedule
Schedule
.
const once: Schedule.Schedule<void, unknown, never>

A schedule that recurs one time.

once
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, void>(action: Effect.Effect<void, never, never>, schedule: Schedule.Schedule<void, void, never>) => void
log
(
const action: Effect.Effect<void, never, never>
action
,
const schedule: Schedule.Schedule<void, unknown, never>
schedule
)
39
/*
40
Output:
41
delay: 0
42
#1 delay: 0 < once
43
*/

A schedule that only recurs the specified number of times.

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 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)
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
#4 delay: 0
46
#5 delay: 0
47
*/

In the context of scheduling, two commonly used schedules are spaced and fixed. While they both involve recurring at specific intervals, they have a fundamental difference in how they determine the timing of repetitions.

The spaced schedule creates a recurring pattern where each repetition is spaced apart by a specified duration. This means that there is a delay between the completion of one repetition and the start of the next. The duration between repetitions remains constant, providing a consistent spacing pattern.

On the other hand, the fixed schedule recurs on a fixed interval, regardless of the duration of the actions or the completion time of previous repetitions. It operates independently of the execution time, ensuring a regular recurrence at the specified interval.

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

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 spaced: (duration: DurationInput) => Schedule.Schedule<number>

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

spaced
("200 millis")
37
const
const action: Effect.Effect<void, never, never>
action
=
import Effect
Effect
.
const delay: <void, never, never>(self: Effect.Effect<void, never, never>, duration: DurationInput) => Effect.Effect<void, never, never> (+1 overload)

Returns an effect that is delayed from this effect by the specified `Duration`.

delay
(
import Effect
Effect
.
(alias) const void: Effect.Effect<void, never, never> export void
void
, "100 millis")
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: 100
42
#1 delay: 300 < spaced
43
#2 delay: 300
44
#3 delay: 300
45
#4 delay: 300
46
#5 delay: 300
47
#6 delay: 300
48
#7 delay: 300
49
#8 delay: 300
50
#9 delay: 300
51
...
52
*/

The first delay is approximately 100 milliseconds, as the initial execution is not affected by the schedule. Subsequent delays are approximately 200 milliseconds apart, demonstrating the effect of the spaced schedule.

A schedule that recurs on a fixed interval. Returns the number of repetitions of the schedule so far.

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 fixed: (interval: DurationInput) => Schedule.Schedule<number>

A schedule that recurs on a fixed interval. Returns the number of repetitions of the schedule so far. If the action run between updates takes longer than the interval, then the action will be run immediately, but re-runs will not "pile up". ``` |-----interval-----|-----interval-----|-----interval-----| |---------action--------||action|-----|action|-----------| ```

fixed
("200 millis")
37
const
const action: Effect.Effect<void, never, never>
action
=
import Effect
Effect
.
const delay: <void, never, never>(self: Effect.Effect<void, never, never>, duration: DurationInput) => Effect.Effect<void, never, never> (+1 overload)

Returns an effect that is delayed from this effect by the specified `Duration`.

delay
(
import Effect
Effect
.
(alias) const void: Effect.Effect<void, never, never> export void
void
, "100 millis")
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: 100
42
#1 delay: 300 < fixed
43
#2 delay: 200
44
#3 delay: 200
45
#4 delay: 200
46
#5 delay: 200
47
#6 delay: 200
48
#7 delay: 200
49
#8 delay: 200
50
#9 delay: 200
51
...
52
*/

The first delay is approximately 100 milliseconds, as the initial execution is not affected by the schedule. Subsequent delays are consistently around 200 milliseconds apart, demonstrating the effect of the fixed schedule.

A schedule that recurs using exponential backoff.

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 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: 10 < exponential
43
#2 delay: 20
44
#3 delay: 40
45
#4 delay: 80
46
#5 delay: 160
47
#6 delay: 320
48
#7 delay: 640
49
#8 delay: 1280
50
#9 delay: 2560
51
...
52
*/

A schedule that always recurs, increasing delays by summing the preceding two delays (similar to the fibonacci sequence). Returns the current duration 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, unknown, never>
schedule
=
import Schedule
Schedule
.
const fibonacci: (one: DurationInput) => Schedule.Schedule<Duration>

A schedule that always recurs, increasing delays by summing the preceding two delays (similar to the fibonacci sequence). Returns the current duration between recurrences.

fibonacci
("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: 10 < fibonacci
43
#2 delay: 10
44
#3 delay: 20
45
#4 delay: 30
46
#5 delay: 50
47
#6 delay: 80
48
#7 delay: 130
49
#8 delay: 210
50
#9 delay: 340
51
...
52
*/