Function: isThenable()
API / @xmachines/core / utils / isThenable
function isThenable<T>(value): value is PromiseLike<T>;Defined in: packages/core/src/utils/is-thenable.ts:20
Tells if a value is a thenable, so that the caller can wait for it.
A declared type such as void | Promise<void> says nothing at run time: a real
implementation returns a promise, and a test double returns nothing. The function
therefore probes the value for a callable then, which is the test that await
applies too.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to test. |
Returns
value is PromiseLike<T>
true when the value has a callable then method.
Example
import { isThenable } from "@xmachines/core/utils";
const result = router.load();if (isThenable(result)) await result;