[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:846](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Task.ts#L846)

`Fiber` is a handle to a running [Task](https://evolu.dev/docs/api-reference/common/Task/type-aliases/Task) that can be awaited, aborted, or
disposed.

### Example

```ts
await using run = createRun();

// Await to get Result
const result = await run(fetchData);

// Abort manually
const fiber = run(longRunningTask);
fiber.abort();
const aborted = await fiber; // Result contains AbortError (unless unabortable)

// Auto-abort with `using`
{
  using background = run(backgroundSync);
  await someOtherWork();
} // background.abort() called automatically here

// Run child tasks in fiber's scope
fiber.run(childTask);

// Monitor via the Run
fiber.run.onEvent = (event) => {
  // handle event
};
```

Because `Fiber` is a [PromiseLike](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables) object, Fibers can be composed with
`Promise.all`, `Promise.race`, etc.

Microtask timing: Run wraps the Task's promise with `.then` and `.finally`,
which adds microtasks between Task completion and Fiber settlement. Do not
write code that relies on a specific number of microtask yields between
Tasks. Use explicit synchronization primitives instead.

## Extends

- [`PromiseLike`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables)\<[`Result`](https://evolu.dev/docs/api-reference/common/Result/type-aliases/Result)\<`T`,
  \| `E`
  \| [`AbortError`](https://evolu.dev/docs/api-reference/common/Task/interfaces/AbortError)\>\>.[`Disposable`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management)

## Methods

<a id="dispose"></a>

### \[dispose\]()

```ts
dispose: void;
```

Defined in: node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.disposable.d.ts:36

#### Inherited from

```ts
Disposable.[dispose]
```

---

<a id="abort"></a>

### abort()

```ts
abort(reason?: unknown): void;
```

Defined in: [packages/common/src/Task.ts:894](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Task.ts#L894)

Requests abort for this Fiber (and any child it started).

### Example

```ts
const fiber = run(fetchData);
fiber.abort();
const result = await fiber; // err(AbortError)
```

When abort is requested, the Fiber's result becomes [AbortError](https://evolu.dev/docs/api-reference/common/Task/variables/AbortError) even
if the Task completed successfully. This keeps behavior predictable —
calling `abort()` always yields `AbortError`.

The optional reason is stored in `AbortError.reason`. Since any value can
be passed, abort reasons are `unknown` — use typed errors for business
logic. To inspect the reason, use type guards like
`RaceLostError.is(reason)`.

Abort is idempotent — calling multiple times has no additional effect
beyond the first call.

### getState()

```ts
getState(): RunState<T, E>;
```

Defined in: [packages/common/src/Task.ts:897](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Task.ts#L897)

Returns the current [RunState](https://evolu.dev/docs/api-reference/common/Task/type-aliases/RunState) of this Fiber's [Run](https://evolu.dev/docs/api-reference/common/Task/interfaces/Run).

## Properties

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

### run

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

Defined in: [packages/common/src/Task.ts:869](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Task.ts#L869)

A [Run](https://evolu.dev/docs/api-reference/common/Task/interfaces/Run) of this Fiber.

Tasks run via this Run are aborted when the Fiber ends.

### Example

```ts
const fiber = run(longRunningTask);

// helperTask is aborted when longRunningTask ends
fiber.run(helperTask);

// Monitor this Fiber's Run
fiber.run.onEvent = (event) => {
  console.log(event);
};
```

---

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

### then

```ts
readonly then: <TResult1, TResult2>(onfulfilled?:
  | ((value: Result) =>
  | TResult1
  | PromiseLike<TResult1>)
  | null, onrejected?:
  | ((reason: any) =>
  | TResult2
  | PromiseLike<TResult2>)
| null) => PromiseLike<TResult1 | TResult2>;
```

Defined in: [packages/common/src/Task.ts:848](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Task.ts#L848)

Attaches callbacks for the resolution and/or rejection of the Promise.

#### Overrides

```ts
PromiseLike.then;
```