MCPcopy Create free account
hub / github.com/Effect-TS/effect / sleep

Method sleep

packages/effect/src/TestClock.ts:193–213  ·  view source on GitHub ↗

* Semantically blocks the current fiber until the clock time is equal to or * greater than the specified duration. Once the clock time is adjusted to * on or after the duration, the fiber will automatically be resumed.

(durationInput: Duration.DurationInput)

Source from the content-addressed store, hash-verified

191 * on or after the duration, the fiber will automatically be resumed.
192 */
193 sleep(durationInput: Duration.DurationInput): Effect.Effect<void> {
194 const duration = Duration.decode(durationInput)
195 return core.flatMap(core.deferredMake<void>(), (deferred) =>
196 pipe(
197 ref.modify(this.clockState, (data) => {
198 const end = data.instant + Duration.toMillis(duration)
199 if (end > data.instant) {
200 return [
201 true,
202 makeData(data.instant, pipe(data.sleeps, Chunk.prepend([end, deferred] as const)))
203 ] as const
204 }
205 return [false, data] as const
206 }),
207 core.flatMap((shouldAwait) =>
208 shouldAwait ?
209 pipe(this.warningStart(), core.zipRight(core.deferredAwait(deferred))) :
210 pipe(core.deferredSucceed(deferred, void 0), core.asVoid)
211 )
212 ))
213 }
214 /**
215 * Returns a list of the times at which all queued effects are scheduled to
216 * resume.

Callers

nothing calls this directly

Calls 5

warningStartMethod · 0.95
makeDataFunction · 0.85
decodeMethod · 0.80
pipeFunction · 0.70
modifyMethod · 0.65

Tested by

no test coverage detected