API reference › @evolu/common › Types › Awaitable
type Awaitable<T> = T | PromiseLike<T>;
Defined in: packages/common/src/Types.ts:385
A value that can be awaited.
Use when a function may complete synchronously or asynchronously depending on runtime conditions (e.g., cache hit vs network fetch).
Sync and async completion
import { assertEqual, isPromiseLike, type Awaitable } from "@evolu/common";
const cache = new Map([["cached", "from cache"]]);
const getData = (id: string): Awaitable<string> =>
cache.get(id) ?? Promise.resolve(`fetched ${id}`);
const fetched = await getData("missing");
const result = getData("cached");
const cached = isPromiseLike(result) ? await result : result;
assertEqual(fetched, "fetched missing");
assertEqual(cached, "from cache");