Built-In Schedules
To demonstrate the functionality of different schedules, we will use the following helper function that logs the delay between executions.
1import { import Effect
Effect, import Schedule
Schedule, import TestClock
TestClock, import Fiber
Fiber, import TestContext
TestContext } from "effect"2
3const 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>(4 (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>,5 (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>6): void => {27 collapsed lines
7 let let start: number
start = 08 let let i: number
i = 09
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>
action14 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.
currentTimeMillis15 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 === 017 ? `delay: ${const now: number
now - let start: number
start}`18 : let i: number
i === 1019 ? "..."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
now24 }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.
fork30 )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>
Executes an effect and returns a `Promise` that resolves with the result.
Use `runPromise` when working with asynchronous effects and you need to integrate with code that uses Promises.
If the effect fails, the returned Promise will be rejected with the error.
runPromise)34}
A schedule that repeats indefinitely, producing the number of recurrences each time it runs.
Example (Forever Recurring Schedule)
1import { import Effect
Effect, import Schedule
Schedule, import TestClock
TestClock, import Fiber
Fiber, import TestContext
TestContext } from "effect"2
32 collapsed lines
3const 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>(4 (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>,5 (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>6): void => {7 let let start: number
start = 08 let let i: number
i = 09
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>
action14 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.
currentTimeMillis15 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 === 017 ? `delay: ${const now: number
now - let start: number
start}`18 : let i: number
i === 1019 ? "..."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
now24 }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.
fork30 )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>
Executes an effect and returns a `Promise` that resolves with the result.
Use `runPromise` when working with asynchronous effects and you need to integrate with code that uses Promises.
If the effect fails, the returned Promise will be rejected with the error.
runPromise)34}35
36const 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.
forever37const const action: Effect.Effect<void, never, never>
action = import Effect
Effect.(alias) const void: Effect.Effect<void, never, never>
export void
void38const 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/*40Output:41delay: 042#1 delay: 0 < forever43#2 delay: 044#3 delay: 045#4 delay: 046#5 delay: 047#6 delay: 048#7 delay: 049#8 delay: 050#9 delay: 051...52*/
A schedule that recurs only once.
Example (Single Recurrence Schedule)
1import { import Effect
Effect, import Schedule
Schedule, import TestClock
TestClock, import Fiber
Fiber, import TestContext
TestContext } from "effect"2
32 collapsed lines
3const 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>(4 (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>,5 (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>6): void => {7 let let start: number
start = 08 let let i: number
i = 09
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>
action14 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.
currentTimeMillis15 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 === 017 ? `delay: ${const now: number
now - let start: number
start}`18 : let i: number
i === 1019 ? "..."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
now24 }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.
fork30 )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>
Executes an effect and returns a `Promise` that resolves with the result.
Use `runPromise` when working with asynchronous effects and you need to integrate with code that uses Promises.
If the effect fails, the returned Promise will be rejected with the error.
runPromise)34}35
36const const schedule: Schedule.Schedule<void, unknown, never>
schedule = import Schedule
Schedule.const once: Schedule.Schedule<void, unknown, never>
A schedule that recurs one time.
once37const const action: Effect.Effect<void, never, never>
action = import Effect
Effect.(alias) const void: Effect.Effect<void, never, never>
export void
void38const 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/*40Output:41delay: 042#1 delay: 0 < once43*/
A schedule that repeats a specified number of times.
Example (Fixed Number of Recurrences)
1import { import Effect
Effect, import Schedule
Schedule, import TestClock
TestClock, import Fiber
Fiber, import TestContext
TestContext } from "effect"2
32 collapsed lines
3const 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>(4 (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>,5 (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>6): void => {7 let let start: number
start = 08 let let i: number
i = 09
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>
action14 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.
currentTimeMillis15 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 === 017 ? `delay: ${const now: number
now - let start: number
start}`18 : let i: number
i === 1019 ? "..."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
now24 }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.
fork30 )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>
Executes an effect and returns a `Promise` that resolves with the result.
Use `runPromise` when working with asynchronous effects and you need to integrate with code that uses Promises.
If the effect fails, the returned Promise will be rejected with the error.
runPromise)34}35
36const 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)37const const action: Effect.Effect<void, never, never>
action = import Effect
Effect.(alias) const void: Effect.Effect<void, never, never>
export void
void38const 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/*40Output:41delay: 042#1 delay: 0 < recurs43#2 delay: 044#3 delay: 045#4 delay: 046#5 delay: 047*/
You can use spaced
or fixed
schedules to specify intervals between recurrences. The difference lies in how the interval is measured: spaced
delays each repetition from the end of the previous one, while fixed
ensures regular intervals, regardless of how long the previous effect took.
A schedule that repeats indefinitely, each repetition spaced the specified duration from the last run.
Example (Recurring with Delay Between Executions)
1import { import Effect
Effect, import Schedule
Schedule, import TestClock
TestClock, import Fiber
Fiber, import TestContext
TestContext } from "effect"2
32 collapsed lines
3const 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>(4 (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>,5 (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>6): void => {7 let let start: number
start = 08 let let i: number
i = 09
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>
action14 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.
currentTimeMillis15 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 === 017 ? `delay: ${const now: number
now - let start: number
start}`18 : let i: number
i === 1019 ? "..."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
now24 }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.
fork30 )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>
Executes an effect and returns a `Promise` that resolves with the result.
Use `runPromise` when working with asynchronous effects and you need to integrate with code that uses Promises.
If the effect fails, the returned Promise will be rejected with the error.
runPromise)34}35
36const 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")37const 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")38const 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/*40Output:41delay: 10042#1 delay: 300 < spaced43#2 delay: 30044#3 delay: 30045#4 delay: 30046#5 delay: 30047#6 delay: 30048#7 delay: 30049#8 delay: 30050#9 delay: 30051...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 at fixed intervals. Returns the number of repetitions of the schedule so far.
Example (Fixed Interval Recurrence)
1import { import Effect
Effect, import Schedule
Schedule, import TestClock
TestClock, import Fiber
Fiber, import TestContext
TestContext } from "effect"2
32 collapsed lines
3const 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>(4 (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>,5 (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>6): void => {7 let let start: number
start = 08 let let i: number
i = 09
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>
action14 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.
currentTimeMillis15 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 === 017 ? `delay: ${const now: number
now - let start: number
start}`18 : let i: number
i === 1019 ? "..."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
now24 }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.
fork30 )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>
Executes an effect and returns a `Promise` that resolves with the result.
Use `runPromise` when working with asynchronous effects and you need to integrate with code that uses Promises.
If the effect fails, the returned Promise will be rejected with the error.
runPromise)34}35
36const 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")37const 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")38const 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/*40Output:41delay: 10042#1 delay: 300 < fixed43#2 delay: 20044#3 delay: 20045#4 delay: 20046#5 delay: 20047#6 delay: 20048#7 delay: 20049#8 delay: 20050#9 delay: 20051...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, with each delay increasing exponentially.
Example (Exponential Backoff Schedule)
1import { import Effect
Effect, import Schedule
Schedule, import TestClock
TestClock, import Fiber
Fiber, import TestContext
TestContext } from "effect"2
32 collapsed lines
3const 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>(4 (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>,5 (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>6): void => {7 let let start: number
start = 08 let let i: number
i = 09
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>
action14 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.
currentTimeMillis15 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 === 017 ? `delay: ${const now: number
now - let start: number
start}`18 : let i: number
i === 1019 ? "..."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
now24 }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.
fork30 )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>
Executes an effect and returns a `Promise` that resolves with the result.
Use `runPromise` when working with asynchronous effects and you need to integrate with code that uses Promises.
If the effect fails, the returned Promise will be rejected with the error.
runPromise)34}35
36const 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")37const const action: Effect.Effect<void, never, never>
action = import Effect
Effect.(alias) const void: Effect.Effect<void, never, never>
export void
void38const 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/*40Output:41delay: 042#1 delay: 10 < exponential43#2 delay: 2044#3 delay: 4045#4 delay: 8046#5 delay: 16047#6 delay: 32048#7 delay: 64049#8 delay: 128050#9 delay: 256051...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.
Example (Fibonacci Delay Schedule)
1import { import Effect
Effect, import Schedule
Schedule, import TestClock
TestClock, import Fiber
Fiber, import TestContext
TestContext } from "effect"2
32 collapsed lines
3const 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>(4 (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>,5 (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>6): void => {7 let let start: number
start = 08 let let i: number
i = 09
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>
action14 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.
currentTimeMillis15 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 === 017 ? `delay: ${const now: number
now - let start: number
start}`18 : let i: number
i === 1019 ? "..."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
now24 }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.
fork30 )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>
Executes an effect and returns a `Promise` that resolves with the result.
Use `runPromise` when working with asynchronous effects and you need to integrate with code that uses Promises.
If the effect fails, the returned Promise will be rejected with the error.
runPromise)34}35
36const 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")37const const action: Effect.Effect<void, never, never>
action = import Effect
Effect.(alias) const void: Effect.Effect<void, never, never>
export void
void38const 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/*40Output:41delay: 042#1 delay: 10 < fibonacci43#2 delay: 1044#3 delay: 2045#4 delay: 3046#5 delay: 5047#6 delay: 8048#7 delay: 13049#8 delay: 21050#9 delay: 34051...52*/