diff options
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/index.ts | 1 | ||||
| -rw-r--r-- | src/util/scheduler.ts | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/util/index.ts b/src/util/index.ts index acf8771..dd356fb 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -1 +1,2 @@ export * as D from "./duration"; +export * from "./logger"; 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)(); + }; |
