From 2859955095020b07909b079d34be8a80e7f58ecd Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 2 Jul 2026 11:10:07 -0700 Subject: Backup --- src/util/scheduler.ts | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/util/scheduler.ts') diff --git a/src/util/scheduler.ts b/src/util/scheduler.ts index 9f9f594..476aca0 100644 --- a/src/util/scheduler.ts +++ b/src/util/scheduler.ts @@ -1,24 +1,38 @@ import * as TE from "fp-ts/lib/TaskEither"; -import { pipe } from "fp-ts/lib/function"; -import type { Schedule } from "../canary"; +import { pipe, identity } from "fp-ts/lib/function"; +import type { Job, Schedule } from "../canary"; +import * as RA from "fp-ts/lib/ReadonlyArray"; +import * as T from "fp-ts/lib/Task"; +import type { Separated } from "fp-ts/lib/Separated"; interface ScheduledJob { id: string; - execute: TE.TaskEither; + execute: () => TE.TaskEither; at: Date; schedule: Schedule; } type SchedulerState = ReadonlyArray; +const executeAll = ( + jobs: ReadonlyArray>, +): T.Task, ReadonlyArray>> => + pipe(jobs, RA.wilt(T.ApplicativePar)(identity)); + export const schedulerLoop = (state: SchedulerState): TE.TaskEither => () => { - const loop = (currentState: SchedulerState): TE.TaskEither => + const loop = ( + currentState: SchedulerState, + time: Date, + ): TE.TaskEither => pipe( - executeDueJobs(currentState), - delay(1000), // Delay for 1 second - map((newState) => loop(newState)), + currentState, + RA.filter((job) => job.at <= time), + RA.map(({ execute }) => execute()), + executeAll, + //T.delay(1000), // Delay for 1 second + // map((newState) => loop(newState)), ); return loop(state)(); -- cgit v1.3