ydao
v1.1.2
Published
一个异步流程函数组合函数,让执行流上的功能更加方便的增加以及拆解
Downloads
19
Maintainers
Readme
Function are
函数作用
compose function 将多个函数进行组合,支持async/promise
Using the example
使用例子
let {yili}= require('ydao')
function a() {
return new Promise((res, rej) => {
setTimeout(() => {
rej();
// res(22, 2);
}, 300);
})
}
function b(v, q) {
console.log(v, q, 'vvb');
return 'b'
}
let qq = yili("a-scope", a, 'b-scope', () => { throw new Error(22); console.log(qqqq); return 22 }, 'a-scope', 'b-scope', b);
qq.catch('a', async ({err, next, rej}) => {
console.log(err, 'a报错', '根据对应函数名捕获');
next('a报错');//向后执行
})
qq.catch(1, async ({err, next, rej}) => {
console.log(err, '匿名函数报错', '根据对应函数位置捕获');
next('报错')//向后执行
})
r.scopecatch('a-scope',({err,i})=>{
console.log(err,'a-scope范围内有错误')
})
qq.on('a-scope:end', (s, n) => {
console.log(s, 222, n, 'end')
})
qq(33)
.then((c) => {
console.log('成功' + c)
})
.catch(a => {
console.log('错误')
})