achain
v1.1.4
Published
asynchronous chain function
Downloads
19
Readme
AChain
asynchronous chain function based on Proxy
Usage
npm
npm i achain
or yarn
yarn add achain
const achain = require('achain')
let attr = await achain(promise).attr.asyncFunc().asyncFunc()().attr
Example
Before
async function main() {
let user = await getUser(1)
let userDetail = await user.getDetail()
await userDetail.destroy()
let user = await getUser(2)
let name = user.name
}
After
async function main() {
await achain(getUser(1)).getDetail().destroy()
let name = await achain(getUser(2)).name
}
Before
async function main() {
let res = await fetch('/users.json')
let data = res.json()
}
After
var api = achain(fetch)
async function main() {
let data = await api('/users.json').json()
}
License
MIT