MCPcopy
hub / github.com/Effect-TS/effect / ClockImpl

Class ClockImpl

packages/effect/src/internal/clock.ts:67–92  ·  view source on GitHub ↗

@internal

Source from the content-addressed store, hash-verified

65
66/** @internal */
67class ClockImpl implements Clock.Clock {
68 readonly [ClockTypeId]: Clock.ClockTypeId = ClockTypeId
69
70 unsafeCurrentTimeMillis(): number {
71 return Date.now()
72 }
73
74 unsafeCurrentTimeNanos(): bigint {
75 return processOrPerformanceNow()
76 }
77
78 currentTimeMillis: Effect.Effect<number> = core.sync(() => this.unsafeCurrentTimeMillis())
79
80 currentTimeNanos: Effect.Effect<bigint> = core.sync(() => this.unsafeCurrentTimeNanos())
81
82 scheduler(): Effect.Effect<Clock.ClockScheduler> {
83 return core.succeed(globalClockScheduler)
84 }
85
86 sleep(duration: Duration.Duration): Effect.Effect<void> {
87 return core.async<void>((resume) => {
88 const canceler = globalClockScheduler.unsafeSchedule(() => resume(core.void), duration)
89 return core.asVoid(core.sync(canceler))
90 })
91 }
92}
93
94/** @internal */
95export const make = (): Clock.Clock => new ClockImpl()

Callers

nothing calls this directly

Calls 3

syncMethod · 0.80

Tested by

no test coverage detected