API reference › @evolu/common › Types › Awaitable
type Awaitable<T> = T | PromiseLike<T>;
Defined in: packages/common/src/Types.ts:235
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).
Example
const getData = (id: string): Awaitable<Data> => {
const cached = cache.get(id);
if (cached) return cached; // Sync path
return fetchData(id); // Async path
};
// Always works
const data = await getData(id);
// Or optimize for sync path
const result = getData(id);
const data = isPromiseLike(result) ? await result : result;