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

Function fixed

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

Source from the content-addressed store, hash-verified

974 * @since 2.0.0
975 */
976export const fixed = (interval: Duration.Input): Schedule<number> => {
977 const window = Duration.toMillis(Duration.fromInputUnsafe(interval))
978 return fromStepWithMetadata(effect.sync(() => {
979 let start = 0
980 let lastRun = 0
981 return (meta) =>
982 effect.sync(() => {
983 if (window === 0) {
984 return [meta.attempt - 1, Duration.zero] as const
985 }
986 if (meta.attempt === 1) {
987 start = meta.now
988 lastRun = meta.now + window
989 return [0, Duration.millis(window)] as const
990 }
991 const runningBehind = meta.now > (lastRun + window)
992 const boundary = window - ((meta.now - start) % window)
993 const delay = runningBehind ? 0 : Duration.isZero(Duration.millis(boundary)) ? window : boundary
994 lastRun = runningBehind ? meta.now : meta.now + delay
995 return [meta.attempt - 1, Duration.millis(delay)] as const
996 })
997 }))
998}
999
1000/**
1001 * 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