@essentials/pending
npm i @essentials/pending
A helper function that adds error handling to async/await without having to use try/catch block
Quick Start
import pending from '@essentials/pending'
const someAsyncFunc = async () => {
const [result, error] = await pending(() => Promise.resolve(true))
if (error) {
doSomethingWith(error)
}
return result
}
API
async function pending<
PromiseReturnType extends any = any,
ErrorType extends any = Error
>(
callback: () => Promise<PromiseReturnType>
): Promise<[PromiseReturnType | undefined, ErrorType | undefined]>
Argument | Type | Default | Required | Description |
---|---|---|---|---|
callback | () => Promise<PromiseReturnType> |
undefined |
Yes | A callback or async function that returns the promise you want to gracefully handle errors for. |
LICENSE
MIT