Read this in other languages: English | 简体中文
# use pnpm
$ pnpm install await-to-done
# use npm
$ npm install await-to-done --save
- 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 */)
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]
<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>
Please open an issue here.