async-chain-proxy provides method chain interfaces for accessing async methods.
class A {
async foo () {
console.log('foo')
}
async bar () {
console.log('bar')
}
}
const chainProxy = require('async-chain-proxy')
const obj = chainProxy(new A())
obj.foo().bar().end()
// output
>foo
>bar
class A {
async foo () {
return 'foo'
}
}
const chainProxy = require('async-chain-proxy')
const obj = chainProxy(new A())
obj.foo().result((v) => console.log(v)).end()
// output
>foo
- resultFuncName(default: 'result') : If you don't prefer result function name, you can change.
- endFuncName(default: 'end') : If you don't prefer end function name, you can change.
- onChainFinished(default: null) : this is a callback function that is called after end().
This function is used for receiving result of previous action.
Indicates end of chained actions. If you didn't call end(), all the actions aren't called.
Returns target object.