<A, E, R>(f: (clock: Clock) => Effect<A, E, R>): Effect<A, E, R>Accesses the current Clock service and uses it to run the provided function.
When to use
Use when you need the full Clock service interface to perform multiple time operations or call unsafe variants within a single effect.
Example (Accessing the current Clock service)
import { Clock, Effect } from "effect"
const program = Clock.clockWith((clock) =>
Effect.sync(() => {
const currentTime = clock.currentTimeMillisUnsafe()
console.log(`Current time: ${currentTime}`)
return currentTime
})
)export const const clockWith: <A, E, R>(
f: (clock: Clock) => Effect<A, E, R>
) => Effect<A, E, R>
Accesses the current Clock service and uses it to run the provided function.
When to use
Use when you need the full Clock service interface to perform multiple time
operations or call unsafe variants within a single effect.
Example (Accessing the current Clock service)
import { Clock, Effect } from "effect"
const program = Clock.clockWith((clock) =>
Effect.sync(() => {
const currentTime = clock.currentTimeMillisUnsafe()
console.log(`Current time: ${currentTime}`)
return currentTime
})
)
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: Clock) => 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 effecteffect.const clockWith: <A, E, R>(
f: (
clock: Clock.Clock
) => Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
clockWith