@essentials/pending
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@essentials/pending

Bundlephobia Types NPM Version MIT License

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

Package Sidebar

Install

npm i @essentials/pending

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

8.34 kB

Total Files

11

Last publish

Collaborators

  • jaredlunde