---
title: SourceSpec
description: "Where a Pool gets its work items: the Source."
---

# `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](../authoring-surface.md) 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`](source.md).

**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`](type-sourcenextresult.md). 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`](type-eventdef.md)

  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.
