Hyperlinkv0.9.0-beta.0

Daemon

Daemon.schedulefunctionsrc/Daemon.ts:2132
(windows: ReadonlyArray<ScheduleWindow>): <Self, S extends Spec>(
  tag: HyperlinkTag<Self, S>
) => HyperlinkTag<Self, S & ScheduleGroupSpec>
(source: HyperlinkTag<any, ScheduleHyperlinkSpec>): <
  Self,
  S extends Spec
>(
  tag: HyperlinkTag<Self, S>
) => HyperlinkTag<Self, S>

Attach a schedule to a daemon (pipeable). Two forms, distinguished by argument:

  • inline windows — the daemon owns an in-memory schedule seeded with windows, and its contract gains the schedule verb group (entries / set / add / clear):
class Matches extends Daemon.Tag<Matches>()("app/Matches").pipe(
  Daemon.schedule([Daemon.window(kickoff, final)]),
) {}
  • an external Schedule — the daemon is gated by a shared schedule resource and gains no schedule verbs (they live on the HyperService, which can arm many daemons at once):
class IngestScores extends Daemon.Tag<IngestScores>()("app/IngestScores").pipe(
  Daemon.schedule(SeasonSchedule),
) {}
scheduleSchedule
Source src/Daemon.ts:213222 lines
export function schedule(
  windows: ReadonlyArray<ScheduleWindow>,
): <Self, S extends Spec>(tag: HyperlinkTag<Self, S>) => HyperlinkTag<Self, S & ScheduleGroupSpec>;
export function schedule(
  source: HyperlinkTag<any, ScheduleHyperlinkSpec>,
): <Self, S extends Spec>(tag: HyperlinkTag<Self, S>) => HyperlinkTag<Self, S>;
export function schedule(
  windowsOrSource: ReadonlyArray<ScheduleWindow> | HyperlinkTag<any, any, any>,
): (tag: HyperlinkTag<any, any, any>) => HyperlinkTag<any, any, any> {
  // A type-guard (not bare `Array.isArray`) so the else-branch narrows to the tag: `Array.isArray`
  // alone won't remove a `ReadonlyArray` from the union.
  const isWindows = (
    x: ReadonlyArray<ScheduleWindow> | HyperlinkTag<any, any, any>,
  ): x is ReadonlyArray<ScheduleWindow> => Array.isArray(x);
  if (isWindows(windowsOrSource)) {
    const mode: ScheduleMode = { _tag: "inline", windows: windowsOrSource };
    return (tag) => augmentTag(tag, scheduleGroupFlat, { [scheduleModeSym]: mode });
  }
  const mode: ScheduleMode = { _tag: "reference", source: windowsOrSource };
  // reference form: shape is unchanged — just stamp the mode (identity, like `distributed`).
  return (tag) => Object.assign(tag, { [scheduleModeSym]: mode });
}