当前位置:网站首页>typeScript-promise
typeScript-promise
2022-08-04 22:44:00 【MXM_777】
function add(a:number,b:number) :Promise<number>{
return new Promise((resolve,reject)=>{
if(b % 17 === 0){
reject('bad number')
}
setTimeout(()=>{
resolve(a+b)
},2000)
})
}
function mul(a:number,b:number) :Promise<number>{
return new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve(a*b)
},2000)
})
}
add(2,17).then(res=>{
console.log('2+17',res)
return mul(res,4)
}).then(res=>{
console.log('(2+3)*4',res)
return mul(res,5)
}).then(res=>{
console.log('20*5',res)
}).catch(err=>{
console.log("catch",err)
})
// add(2,3)
// .then(res=>add(res,4))
// .then(res=>add(res,8))
// .then(res=>{
// console.log("redult",res)
// })
边栏推荐
猜你喜欢
随机推荐
文章占位 文章占位
3D建模师为了让甲方爸爸过稿,还可以这么做,就是在赚血汗钱啊
ES 数据聚合、数据同步、集群
golang打开文件和读写文件
老叶的三束玫瑰
Jbpm3.2 开发HelloWorld (简单请假流程)客户端
生成回文数
promise详解
边缘检测——(纯享版)
Redis理解
从“草原牛”到“数字牛”:蒙牛的数字化转型之道
软测人面试 ,HR 会问到哪些问题?学会涨薪3000+
If you can't get your heart, use "distributed lock" to lock your people
panic: reflect: reflect.Value.SetString using value obtained using unexported field
阿里巴巴2022届秋招面试真题和答案!
Both synchronized and ReentrantLock are smooth, because they are reentrant locks, and a thread will not deadlock if it takes the lock multiple times. We need reentrant locks
单片机原理[一] 学好单片机必会的五张图
【游戏建模模型制作全流程】在ZBrush中雕刻恶魔城男性角色模型
测试薪资这么高?刚毕业20K,仅需3.5个月
[Mock Interview - 10 Years of Work] Are more projects an advantage?