1.0.3 • Published 2 years ago
chain_promise_call v1.0.3
chain-promise-call
promise chain 异步函数链式调用 保证链式调用的正确性
函数调用
!async function () {
const chain = new Chain();
async function ts() {
console.log('ts')
}
// 添加匿名函数
chain.add(async () => {
console.log(1);
return 1
});
// 添加声明函数
chain.add(ts);
chain.add(async () => {
console.log(2);
});
chain.add(async (params) => {
console.log(params);
throw new Error('报错');
});
// 报错执行
chain.catch = (err)=>{
console.log(err);
}
// 最终执行
chain.finally(()=>{
});
// 移除函数 匿名函数无法查找 只能移除第一个查找到的匿名函数
chain.pop(ts);
// 运行
chain.run();
}()
包安装
- npm install chain_promise_call