当前位置:网站首页>typeScript-promise
typeScript-promise
2022-08-04 22:48: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)
// })
边栏推荐
- The Record of Reminding myself
- The Record of Reminding myself
- 【3D建模制作技巧分享】ZBrush模型如何添加不同材质
- PID控制器改进笔记之七:改进PID控制器之防超调设定
- 一招包治pycharm DEBUG报错 UnicodeDecodeError: ‘utf-8‘ codec can‘t decode
- Nacos配置中心之客户端长轮询
- 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
- Jbpm3.2 开发HelloWorld (简单请假流程)客户端
- 线上虚拟展馆展示具有哪些优势
- the warmest home
猜你喜欢
随机推荐
One trick to cure pycharm DEBUG error UnicodeDecodeError: 'utf-8' codec can't decode
PowerBI scripture series
【3D建模制作技巧分享】ZBrush纹理贴图怎么导入
2022年全网最全接口自动化测试框架搭建,没有之一
Operations on std::vector
深度学习 RNN架构解析
阿里巴巴2022届秋招面试真题和答案!
MQTT[一]基础知识介绍
软测人面试 ,HR 会问到哪些问题?学会涨薪3000+
Latex快速插入作者ORCID
字节跳动秋招提前批高频面试问题汇总!(内附答案!)
The Record of Reminding myself
【3D建模制作技巧分享】zbrush贴图映射小技巧
现在学习次世代3D游戏建模还能找到高薪好工作吗
限制tensorflow使用Cpu核数
质量管理大师爱德华·戴明博士经典的质量管理14条原则
DREAMWEAVER8 part of the problem solution
【3D建模制作技巧分享】Maya模型如何导入zbrush
JVM memory configuration parameter GC log
Reconfigure the ffmpeg plugin in chrome








