Clock module provides functionality for time-based operations in Effect applications. It offers precise time measurements, scheduling capabilities, and controlled time management for testing scenarios.
Core Capabilities
The Clock service is a core component of the Effect runtime, providing:- Current time access in milliseconds and nanoseconds
- Sleep operations for delaying execution
- Time-based scheduling primitives
- Testable time control through
TestClock
Getting Current Time
Access the current time with millisecond or nanosecond precision.Sleep Operations
Delay execution with non-blocking sleep operations.Measuring Execution Time
Measure the duration of operations using Clock.Using the Clock Service
Access the Clock service directly for more control.Using clockWith
Run functions that need Clock access.API Reference
Clock Service
Clock.Clock: ServiceMap.Reference<Clock>
A reference to the current Clock service in the environment.
Functions
clockWith
currentTimeMillis
currentTimeNanos
Testing with Clock
For testing, Effect providesTestClock to control time deterministically:
