saqqdy / await-to-done

Async await wrapper for easy error handling

Home Page:https://www.saqqdy.com/await-to-done

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Async await wrapper for easy error handling

https://www.saqqdy.com/await-to-done

License:MIT License


Languages

Language:TypeScript 87.5%Language:Shell 12.1%Language:JavaScript 0.4%