[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Task](https://evolu.dev/docs/api-reference/common/Task) › Fiber

Defined in: [packages/common/src/Task.ts:1654](https://github.com/evoluhq/evolu/blob/a18269a1b822c670b507c6a9b73b23eed32551fe/packages/common/src/Task.ts#L1654)

A Promise-backed handle to a [Task](https://evolu.dev/docs/api-reference/common/Task/type-aliases/Task) started by a [Run](https://evolu.dev/docs/api-reference/common/Task/interfaces/Run).

Await a Fiber to use the Task Result in the current control flow. The Fiber
resolves with the Task [Result](https://evolu.dev/docs/api-reference/common/Result/type-aliases/Result) when the Task returns normally. A Fiber
returned by `run(task)` rejects with [AbortError](https://evolu.dev/docs/api-reference/common/Task/variables/AbortError) when the Task observes
abort or when a defect panics the Run tree. Panic uses
[PanicAbortReason](https://evolu.dev/docs/api-reference/common/Task/interfaces/PanicAbortReason); the original defect is available on the reason for
diagnostics. Use [Run.abortable](https://evolu.dev/docs/api-reference/common/Task/interfaces/Run#abortable) when abort or panic should be returned
as an [Err](https://evolu.dev/docs/api-reference/common/Result/interfaces/Err); do not catch AbortError from `run(task)` to model expected
cancellation.

Prefer `await fiber` over `fiber.then()`. Zero-cost async stack traces are
reconstructed from `await` suspension points and selected native Promise
combinators such as `Promise.all`, `Promise.any`, and `Promise.race`, not
from arbitrary `then`/`catch` reaction chains. Awaiting a Fiber preserves the
async-function boundary that links cross-Run defect stack traces; attaching
`then` reactions can lose those frames. See
[Asynchronous stack traces: why await beats Promise#then()](https://mathiasbynens.be/notes/async-stack-traces)
and [V8: Stack trace API](https://v8.dev/docs/stack-trace-api).
Hermes/React Native currently expose only child throw sites, so this
diagnostic stack-linking benefit is unavailable there; use Run monitoring
state, snapshots, and events for cross-Run diagnostics.

Child Fiber results are not implicitly aggregated into parent results. If a
Task starts a child Fiber and returns before awaiting or returning it, the
parent Run still waits for the child during cleanup. A later child defect
panics the root Run and is reported, but the already-returned parent Result
is preserved.

The [run](https://evolu.dev/docs/api-reference/common/Task/interfaces/Fiber#run) property exposes the child Run used to execute the
Task. Use it for monitoring state, snapshots, events, and child lifetime
inspection.

Plain Fibers do not provide abort or disposal controls. Use
[AbortableFiber](https://evolu.dev/docs/api-reference/common/Task/interfaces/AbortableFiber), returned by `Run.abortable` or [Run.daemon](https://evolu.dev/docs/api-reference/common/Task/interfaces/Run#daemon), for
explicit abort and async disposal.

### Example

```ts

await using run = createRun();

const loadUser: Task<string> = () => ok("Ada");

const fiber = run<string, never>(loadUser);
const userResult = await fiber;
const snapshot = fiber.run.snapshot();

expectTypeOf(fiber).toEqualTypeOf<Fiber<string, never>>();
expectOk(userResult, "Ada");
expect(snapshot.id).toBe(fiber.run.id);
```

## Extends

- `Promise`\<[`Result`](https://evolu.dev/docs/api-reference/common/Result/type-aliases/Result)\<`T`, `E`\>\>

## Extended by

- [`AbortableFiber`](https://evolu.dev/docs/api-reference/common/Task/interfaces/AbortableFiber)

## Methods

<a id="catch"></a>

### catch()

```ts
catch<TResult>(onrejected?:
  | ((reason: any) =>
  | TResult
  | PromiseLike<TResult>)
  | null): Promise<
  | Result<T, E>
| 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

```ts
Promise.catch;
```

---

<a id="finally"></a>

### finally()

```ts
finally(onfinally?: (() => void) | null): Promise<Result<T, E>>;
```

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

```ts
Promise.finally;
```

---

<a id="then"></a>

### then()

```ts
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

```ts
Promise.then;
```

## Properties

<a id="tostringtag"></a>

### \[toStringTag\]

```ts
readonly [toStringTag]: string;
```

Defined in: node\_modules/@typescript/old/lib/lib.es2015.symbol.wellknown.d.ts:174

#### Inherited from

```ts
Promise.[toStringTag]
```

---

<a id="run"></a>

### run

```ts
readonly run: Run<D>;
```

Defined in: [packages/common/src/Task.ts:1657](https://github.com/evoluhq/evolu/blob/a18269a1b822c670b507c6a9b73b23eed32551fe/packages/common/src/Task.ts#L1657)