API reference › @evolu/common › Task › AbortableFiber
Defined in: packages/common/src/Task.ts:1733
A Fiber with explicit abort and async-disposal controls.
Calling .abort() requests abort for the Fiber's child Run. If the
Task observes abort or a defect panics the Run tree, the Fiber resolves with
an Err containing the AbortError. Panic uses
PanicAbortReason; the original defect is available on the reason for
diagnostics.
Use .abort() plus await fiber for manual lifetime control, or await using for a lifetime bounded by the using block. Async disposal calls
.abort() and waits for the Fiber to settle.
Example
import {
AbortError,
createRun,
ok,
sleep,
type AbortableFiber,
type Task,
} from "@evolu/common";
await using run = createRun();
const fetchData: Task<string> = async (run) => {
await run.ok(sleep("1s"));
return ok("data");
};
const fiber = run.abortable<string, never>(fetchData);
expectTypeOf(fiber).toEqualTypeOf<AbortableFiber<string, never>>();
fiber.abort();
const result = await fiber;
assert(!result.ok);
expect(AbortError.is(result.error)).toBe(true);
Extends
Fiber<T, |E|AbortError,D>.AsyncDisposable
Methods
[asyncDispose]()
asyncDispose: PromiseLike<void>;
Defined in: node_modules/@typescript/old/lib/lib.esnext.disposable.d.ts:38
Inherited from
AsyncDisposable.[asyncDispose]
catch()
catch<TResult>(onrejected?:
| ((reason: any) =>
| TResult
| PromiseLike<TResult>)
| null): Promise<
| Result<T,
| E
| AbortError>
| TResult>;
Defined in: node_modules/@typescript/old/lib/lib.es5.d.ts:1562
Attaches a callback for only the rejection of the Promise.
Inherited from
finally()
finally(onfinally?: (() => void) | null): Promise<Result<T,
| E
| AbortError>>;
Defined in: node_modules/@typescript/old/lib/lib.es2018.promise.d.ts:27
Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.
Inherited from
then()
then<TResult1, TResult2>(onfulfilled?:
| ((value: Result) =>
| TResult1
| PromiseLike<TResult1>)
| null, onrejected?:
| ((reason: any) =>
| TResult2
| PromiseLike<TResult2>)
| null): Promise<TResult1 | TResult2>;
Defined in: node_modules/@typescript/old/lib/lib.es5.d.ts:1555
Attaches callbacks for the resolution and/or rejection of the Promise.
Inherited from
Properties
[toStringTag]
readonly [toStringTag]: string;
Defined in: node_modules/@typescript/old/lib/lib.es2015.symbol.wellknown.d.ts:174
Inherited from
abort
readonly abort: (reason?: AbortReason) => void;
Defined in: packages/common/src/Task.ts:1735
run
readonly run: Run<D>;
Defined in: packages/common/src/Task.ts:1657