1.0.0 • Published 4 years ago
@essentials/pending v1.0.0
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
1.0.0
4 years ago