(intervalInput: Duration.DurationInput)
| 753 | |
| 754 | /** @internal */ |
| 755 | export 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 */ |
| 790 | export const fromDelay = (delay: Duration.DurationInput): Schedule.Schedule<Duration.Duration> => duration(delay) |
nothing calls this directly
no test coverage detected
searching dependent graphs…