Skip to content

Op

Op<Args, E, A> = object

Defined in: Core/Op.ts:114

A reusable description of async work — decoupled from execution strategy and lifetime.

Separate concerns:

  • What to do: encoded in the Op via Op.make
  • How to execute: chosen at Op.interpret time (restartable, exclusive, queue, etc.)

An Op never runs on its own. It only executes when passed to Op.interpret, which attaches a concurrency strategy and returns a Manager that owns the execution.

const fetchUser = Op.make(
  (signal) => (id: string) =>
    fetch(`/users/${id}`, { signal }).then(r => {
      if (!r.ok) throw new Error(`${r.status} ${r.statusText}`);
      return r.json() as Promise<User>;
    }),
  { onError: (e) => new ApiError(e) },
);

const manager = Op.interpret(fetchUser, { strategy: "restartable" });
manager.subscribe(state => {
  if (Op.is.pending(state)) showSpinner();
  if (Op.Outcome.is.ok(state)) render(state.value);
  if (Op.Outcome.is.err(state)) showError(state.error);
  if (Op.Outcome.is.nil(state)) resetUI();
});
manager.run(userId);

Args extends readonly unknown[] = readonly unknown[]

E = unknown

A = unknown

readonly [_opBrand]: object

Defined in: Core/Op.ts:120

readonly _args: (…args) => void

…Args

void

readonly _error: () => E

E

readonly _value: () => A

A


readonly optional [toStringTag]?: string

Defined in: Core/Op.ts:119


readonly optional id?: string

Defined in: Core/Op.ts:118

An optional diagnostic identifier for this operation blueprint.