(interval: Duration.Input)
| 974 | * @since 2.0.0 |
| 975 | */ |
| 976 | export 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 |
nothing calls this directly
no test coverage detected