MCPcopy Index your code
hub / github.com/Effect-TS/effect / TestClockImpl

Class TestClockImpl

packages/effect/src/TestClock.ts:131–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129
130/** @internal */
131export class TestClockImpl implements TestClock {
132 [clock.ClockTypeId]: Clock.ClockTypeId = clock.ClockTypeId
133 constructor(
134 readonly clockState: Ref.Ref<Data>,
135 readonly live: Live.TestLive,
136 readonly annotations: Annotations.TestAnnotations,
137 readonly warningState: Synchronized.SynchronizedRef<WarningData.WarningData>,
138 readonly suspendedWarningState: Synchronized.SynchronizedRef<SuspendedWarningData.SuspendedWarningData>
139 ) {
140 this.currentTimeMillis = core.map(
141 ref.get(this.clockState),
142 (data) => data.instant
143 )
144 this.currentTimeNanos = core.map(
145 ref.get(this.clockState),
146 (data) => BigInt(data.instant * 1000000)
147 )
148 }
149
150 /**
151 * Unsafely returns the current time in milliseconds.
152 */
153 unsafeCurrentTimeMillis(): number {
154 return ref.unsafeGet(this.clockState).instant
155 }
156
157 /**
158 * Unsafely returns the current time in nanoseconds.
159 */
160 unsafeCurrentTimeNanos(): bigint {
161 return BigInt(Math.floor(this.unsafeCurrentTimeMillis() * 1000000))
162 }
163
164 /**
165 * Returns the current clock time in milliseconds.
166 */
167 currentTimeMillis: Effect.Effect<number>
168
169 /**
170 * Returns the current clock time in nanoseconds.
171 */
172 currentTimeNanos: Effect.Effect<bigint>
173
174 /**
175 * Saves the `TestClock`'s current state in an effect which, when run, will
176 * restore the `TestClock` state to the saved state.
177 */
178 get save(): Effect.Effect<Effect.Effect<void>> {
179 return core.map(ref.get(this.clockState), (data) => ref.set(this.clockState, data))
180 }
181 /**
182 * Sets the current clock time to the specified instant. Any effects that
183 * were scheduled to occur on or before the new time will be run in order.
184 */
185 setTime(instant: number): Effect.Effect<void> {
186 return core.zipRight(this.warningDone(), this.run(() => instant))
187 }
188 /**

Callers

nothing calls this directly

Calls 2

syncMethod · 0.80
resumeFunction · 0.70

Tested by

no test coverage detected