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

Function fixed

packages/effect/src/Schedule.ts:933–955  ·  view source on GitHub ↗
(interval: Duration.Input)

Source from the content-addressed store, hash-verified

931 * @since 2.0.0
932 */
933export const fixed = (interval: Duration.Input): Schedule<number> => {
934 const window = Duration.toMillis(Duration.fromInputUnsafe(interval))
935 return fromStepWithMetadata(effect.sync(() => {
936 let start = 0
937 let lastRun = 0
938 return (meta) =>
939 effect.sync(() => {
940 if (window === 0) {
941 return [meta.attempt - 1, Duration.zero] as const
942 }
943 if (meta.attempt === 1) {
944 start = meta.now
945 lastRun = meta.now + window
946 return [0, Duration.millis(window)] as const
947 }
948 const runningBehind = meta.now > (lastRun + window)
949 const boundary = window - ((meta.now - start) % window)
950 const delay = runningBehind ? 0 : boundary === 0 ? window : boundary
951 lastRun = runningBehind ? meta.now : meta.now + delay
952 return [meta.attempt - 1, Duration.millis(delay)] as const
953 })
954 }))
955}
956
957/**
958 * Returns a new `Schedule` that maps each schedule decision to a new output

Callers

nothing calls this directly

Calls 2

fromStepWithMetadataFunction · 0.85
syncMethod · 0.45

Tested by

no test coverage detected