<A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>Retrieves the Clock service from the context and provides it to the
specified effectful function.
Example (Accessing the Clock service)
import { Console, Effect } from "effect"
const program = Effect.clockWith((clock) =>
clock.currentTimeMillis.pipe(
Effect.map((currentTime) => `Current time is: ${currentTime}`),
Effect.tap(Console.log)
)
)
Effect.runFork(program)
// Example Output:
// Current time is: 1735484929744export const const clockWith: <A, E, R>(
f: (clock: Clock) => Effect<A, E, R>
) => Effect<A, E, R>
Retrieves the Clock service from the context and provides it to the
specified effectful function.
Example (Accessing the Clock service)
import { Console, Effect } from "effect"
const program = Effect.clockWith((clock) =>
clock.currentTimeMillis.pipe(
Effect.map((currentTime) => `Current time is: ${currentTime}`),
Effect.tap(Console.log)
)
)
Effect.runFork(program)
// Example Output:
// Current time is: 1735484929744
clockWith: <function (type parameter) A in <A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>R>(
f: (clock: Clock) => Effect<A, E, R>f: (clock: Clock(parameter) clock: {
currentTimeMillisUnsafe: () => number;
currentTimeMillis: Effect<number>;
currentTimeNanosUnsafe: () => bigint;
currentTimeNanos: Effect<bigint>;
sleep: (duration: Duration.Duration) => Effect<void>;
}
clock: import ClockClock) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>R>
) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>R> = import internalinternal.const clockWith: <A, E, R>(
f: (
clock: Clock.Clock
) => Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
clockWith