API reference / @evolu/common / Task / isAsync
Function: isAsync()
function isAsync<T>(
value,
): value is T extends PromiseLike<unknown> ? never : PromiseLike<T>;
Defined in: packages/common/src/Task.ts:883
Type guard to check if a MaybeAsync value is async (a promise).
This function narrows the type of a MaybeAsync value, allowing you to
conditionally await only when necessary.
Example
const getData = (id: string): MaybeAsync<Data> => {
const cached = cache.get(id);
if (cached) return cached; // Sync path
return fetchData(id); // Async path
};
const result = getData(id);
const data = isAsync(result) ? await result : result;
// No microtask overhead when cached!
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
value | MaybeAsync<T> |
Returns
value is T extends PromiseLike<unknown> ? never : PromiseLike<T>