Skip to content

SourceSpec ​

Type, in @jr2/orchestrator/src/pool.ts. The signature of an export, or a type that it names, names this type. The Authoring surface page lists each export. This type is not an export of @jr2/orchestrator, so a workflow module does not import it by name.

ts
type SourceSpec<T> = {
  next:
    | PromiseActorLogic<SourceNextResult<T>, { active: string[] }>
    | PromiseActorLogic<{ item: T | null; open: number }, { active: string[] }>
    | PromiseActorLogic<T | null, { active: string[] }>
    | PromiseActorLogic<null, { active: string[] }>;
  wake?: EventDef;
  pollEvery?: number;
};

Where a Pool gets its work items: the Source. Make one with source.

Fields

  • next: PromiseActorLogic<SourceNextResult<T>, { active: string[]; }> | PromiseActorLogic<{ item: T | null; open: number; }, { active: string[]; }> | PromiseActorLogic<T | null, { active: string[]; }> | PromiseActorLogic<null, { active: string[]; }>

    Claim the next ready item. Write it as an xstate promise actor, fromPromise(async ({ input }) => …). Its input is { active }: the ids of the items that workers have now, which it must not give again. It must also not give again an item that a worker finished. It resolves to a SourceNextResult. The Pool calls it when the run starts, after each claim, and when a worker settles. While workers run and no item is ready, it also calls it on wake and every pollEvery.

  • wake (optional): EventDef

    An external event, made with defineEvent, that tells the Pool that new work is ready, for example from a webhook or jr2 send. While workers run and no item is ready, it makes the Pool call next at once. The Pool serves it as a Gate named source for the whole run (<path>.source when the Pool is composed in another Machine). Default: none.

  • pollEvery (optional): number

    While workers run and no item is ready, call next again after this many milliseconds. Use it for a Source whose items change while the run waits. Default: none, so the Pool calls next again only when a worker settles or wake comes.

The docs of Kit version 0.5.1. Each page is also at its .md URL.