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