diff options
| author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-07-28 14:10:38 -0700 |
|---|---|---|
| committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-07-28 14:10:38 -0700 |
| commit | ad74ff999589e0df2b60ba6e94362ed5215af312 (patch) | |
| tree | a10800668c18c7b9f7222ac9fabbca01b941f834 /src/util/scheduler.ts | |
| parent | 452c41a75aa2f9036614d677fda3867221db959e (diff) | |
| download | mon.hatecomputers.club-ad74ff999589e0df2b60ba6e94362ed5215af312.tar.gz mon.hatecomputers.club-ad74ff999589e0df2b60ba6e94362ed5215af312.zip | |
something
Diffstat (limited to 'src/util/scheduler.ts')
| -rw-r--r-- | src/util/scheduler.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util/scheduler.ts b/src/util/scheduler.ts new file mode 100644 index 0000000..9f9f594 --- /dev/null +++ b/src/util/scheduler.ts @@ -0,0 +1,25 @@ +import * as TE from "fp-ts/lib/TaskEither"; +import { pipe } from "fp-ts/lib/function"; +import type { Schedule } from "../canary"; + +interface ScheduledJob { + id: string; + execute: TE.TaskEither<Error, boolean>; + at: Date; + schedule: Schedule; +} + +type SchedulerState = ReadonlyArray<ScheduledJob>; + +export const schedulerLoop = + (state: SchedulerState): TE.TaskEither<Error, void> => + () => { + const loop = (currentState: SchedulerState): TE.TaskEither<Error, void> => + pipe( + executeDueJobs(currentState), + delay(1000), // Delay for 1 second + map((newState) => loop(newState)), + ); + + return loop(state)(); + }; |
