await-to-done
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

await-to-done

Async await wrapper for easy error handling

NPM version Codacy Badge typescript Test coverage npm download gzip License

Sonar

Read this in other languages: English | 简体中文

Installing

# use pnpm
$ pnpm install await-to-done

# use npm
$ npm install await-to-done --save

Usage

Simple Usage

  1. ES6 module
import to from 'await-to-done'

const [err, data] = await to(/* promise function */)
  1. Node.js require
const to = require('await-to-done')

const [err, data] = await to(/* promise function */)

Multiple Promises

import to from 'await-to-done'

const bar = () => new Promise<boolean>()
const foo = () => new Promise<string>()

const [err, data] = await to(bar(), foo()) // data = [boolean, string]
// or pass in an Array
const [err, data] = await to([bar(), foo()]) // data = [boolean, string]

Using unpkg CDN

<script src="https://unpkg.com/await-to-done@latest/dist/index.global.prod.js"></script>
<script>
  ;(async () => {
    const to = window.awaitToDone
    const [err, data] = await to(/* promise function */)
  })()
</script>

Support & Issues

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i await-to-done

Weekly Downloads

19

Version

1.1.1

License

MIT

Unpacked Size

15.1 kB

Total Files

11

Last publish

Collaborators

  • saqqdy