Search Docs
awaitTo
Utility function that wraps a Promise or value to return a tuple of [error, data] instead of throwing.
import { awaitTo } from 'funtool'; // Basic usage with async function const [err, data] = await awaitTo(fetchData()); if (err) { console.error('Error:', err); } else { console.log('Data:', data); } // With regular value const [err2, value] = await awaitTo(42); console.log(value); // 42
function awaitTo<T>( promiseOrValue: Promise<T> | T ): Promise<[unknown, undefined] | [null, T]>
promiseOrValue
Returns a Promise that resolves to a tuple: