Skip to content

abortable

abortable<A>(factory): object

Defined in: Core/Task.ts:483

Creates a Task paired with an abort handle. Calling abort() cancels the current in-flight call immediately. Unlike a one-shot abort, calling task() again after abort() starts a fresh call with a new signal.

Each invocation of task() automatically cancels the previous in-flight call, making it safe to call repeatedly (e.g. on user input) without leaking promises.

If an outer signal is also present (passed at the call site), aborting it propagates into the internal controller.

A

(signal) => Promise<A>

object

abort: () => void

void

task: Task<A>

const { task: poll, abort } = Task.abortable(
  (signal) => waitForEvent(bus, "ready", { signal }),
);

onUnmount(abort);
await poll();