Skip to content

Op

Op<Args, E, A> = object

Defined in: Core/Op.ts:113

A reusable description of asynchronous work.

Op.interpret creates a manager that runs the work and controls overlapping calls. Each caller receives its own outcome, while the manager exposes its current state to subscribers.

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

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:119

readonly _args: (…args) => void

…Args

void

readonly _error: () => E

E

readonly _value: () => A

A


readonly optional [toStringTag]?: string

Defined in: Core/Op.ts:118


readonly optional id?: string

Defined in: Core/Op.ts:117

An optional diagnostic identifier for this operation blueprint.