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

Function fixed

packages/effect/src/internal/schedule.ts:755–787  ·  view source on GitHub ↗
(intervalInput: Duration.DurationInput)

Source from the content-addressed store, hash-verified

753
754/** @internal */
755export const fixed = (intervalInput: Duration.DurationInput): Schedule.Schedule<number> => {
756 const interval = Duration.decode(intervalInput)
757 const intervalMillis = Duration.toMillis(interval)
758 return makeWithState<[Option.Option<[number, number]>, number], unknown, number>(
759 [Option.none(), 0],
760 (now, _, [option, n]) =>
761 core.sync(() => {
762 switch (option._tag) {
763 case "None": {
764 return [
765 [Option.some([now, now + intervalMillis]), n + 1],
766 n,
767 ScheduleDecision.continueWith(Interval.after(now + intervalMillis))
768 ]
769 }
770 case "Some": {
771 const [startMillis, lastRun] = option.value
772 const runningBehind = now > (lastRun + intervalMillis)
773 const boundary = Equal.equals(interval, Duration.zero)
774 ? interval
775 : Duration.millis(intervalMillis - ((now - startMillis) % intervalMillis))
776 const sleepTime = Equal.equals(boundary, Duration.zero) ? interval : boundary
777 const nextRun = runningBehind ? now : now + Duration.toMillis(sleepTime)
778 return [
779 [Option.some([startMillis, nextRun]), n + 1],
780 n,
781 ScheduleDecision.continueWith(Interval.after(nextRun))
782 ]
783 }
784 }
785 })
786 )
787}
788
789/** @internal */
790export const fromDelay = (delay: Duration.DurationInput): Schedule.Schedule<Duration.Duration> => duration(delay)

Callers

nothing calls this directly

Calls 3

makeWithStateFunction · 0.85
decodeMethod · 0.80
syncMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…