Package detail

await-to-done

saqqdy77MIT1.1.1

Async await wrapper for easy error handling

promise, await-to-js, await-to, await-error

readme

# await-to-done Async await wrapper for easy error handling NPM version Codacy Badge typescript Test coverage npm download gzip License Sonar
### DocumentationChange Log 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

changelog

Change logs

2024.05.30 v1.1.1

  1. docs work
  2. use pnpm v9

2024.05.30 v1.1.0

  1. fix types
  2. upgrade all packages

2023.11.13 v1.0.2

  1. Code Optimization

2023.11.03 v1.0.1

  1. rename function name to awaitToDone

2023.11.03 v1.0.0

  1. create project
  2. README.md