Skip to content

Latest commit

 

History

History
104 lines (73 loc) · 3.02 KB

README-zh_CN.md

File metadata and controls

104 lines (73 loc) · 3.02 KB

await-to-done

Async await 封装器可轻松处理错误

NPM version Codacy Badge typescript Test coverage npm download gzip License

Sonar

使用其他语言阅读:English | 简体中文

安装

# 使用pnpm
$ pnpm install await-to-done

# 使用npm
$ npm install await-to-done --save

使用

简单用法

  1. ES6 模块方式引入
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 */)

传入多个Promise

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]
// 或者传入数组形式
const [err, data] = await to([bar(), foo()]) // data = [boolean, string]

使用 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>

问题和支持

Please open an issue here.

License

MIT