API reference › @evolu/common › Types › Awaitable
type Awaitable<T> = T | PromiseLike<T>;
Defined in: packages/common/src/Types.ts:356
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 { 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;
expect(fetched).toBe("fetched missing");
expect(cached).toBe("from cache");