From ad74ff999589e0df2b60ba6e94362ed5215af312 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 28 Jul 2024 14:10:38 -0700 Subject: something --- src/util/scheduler.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/util/scheduler.ts (limited to 'src/util/scheduler.ts') 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; + at: Date; + schedule: Schedule; +} + +type SchedulerState = ReadonlyArray; + +export const schedulerLoop = + (state: SchedulerState): TE.TaskEither => + () => { + const loop = (currentState: SchedulerState): TE.TaskEither => + pipe( + executeDueJobs(currentState), + delay(1000), // Delay for 1 second + map((newState) => loop(newState)), + ); + + return loop(state)(); + }; -- cgit v1.3