await-to-done
v1.1.1
Published
Async await wrapper for easy error handling
Downloads
164
Maintainers
Readme
await-to-done
Async await wrapper for easy error handling
Documentation • Change 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
- ES6 module
import to from 'await-to-done'
const [err, data] = await to(/* promise function */)
- 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.