| 5990 | const MAX_TIMER_MILLIS = 2 ** 31 - 1 |
| 5991 | |
| 5992 | class ClockImpl implements Clock.Clock { |
| 5993 | currentTimeMillisUnsafe(): number { |
| 5994 | return Date.now() |
| 5995 | } |
| 5996 | readonly currentTimeMillis: Effect.Effect<number> = sync(() => this.currentTimeMillisUnsafe()) |
| 5997 | currentTimeNanosUnsafe(): bigint { |
| 5998 | return wallTimeNanos() |
| 5999 | } |
| 6000 | readonly currentTimeNanos: Effect.Effect<bigint> = sync(() => this.currentTimeNanosUnsafe()) |
| 6001 | monotonicTimeNanosUnsafe(): bigint { |
| 6002 | return monotonicNowNanos() |
| 6003 | } |
| 6004 | readonly monotonicTimeNanos: Effect.Effect<bigint> = sync(() => this.monotonicTimeNanosUnsafe()) |
| 6005 | sleep(duration: Duration.Duration): Effect.Effect<void> { |
| 6006 | return this.sleepMillis(Duration.toMillis(duration)) |
| 6007 | } |
| 6008 | private sleepMillis(millis: number): Effect.Effect<void> { |
| 6009 | if (millis <= 0) return yieldNow |
| 6010 | else if (!Number.isFinite(millis)) return never |
| 6011 | return callback((resume) => { |
| 6012 | const continuation = millis > MAX_TIMER_MILLIS |
| 6013 | ? this.sleepMillis(millis - MAX_TIMER_MILLIS) |
| 6014 | : void_ |
| 6015 | const handle = setTimeout(() => resume(continuation), Math.min(millis, MAX_TIMER_MILLIS)) |
| 6016 | return sync(() => clearTimeout(handle)) |
| 6017 | }) |
| 6018 | } |
| 6019 | } |
| 6020 | |
| 6021 | const nanosPerMilli = BigInt(1_000_000) |
| 6022 |
nothing calls this directly
no test coverage detected