当前位置:网站首页>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)
// })
边栏推荐
- 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
- 【3D建模制作技巧分享】Maya模型如何导入zbrush
- JVM内存配置参数GC日志
- 使用cpolar优化树莓派上的网页(1)
- ffplay视频播放原理分析
- 【游戏建模模型制作全流程】ZBrush蜥蜴模型雕刻教程
- QT 子窗口—>主窗口 信号和槽的交互
- Leaflets of three bouquet of roses
- 边缘检测——(纯享版)
- Jbpm3.2 开发HelloWorld (简单请假流程)客户端
猜你喜欢

【2020】【Paper Notes】Metasurfaces: Multifunctional and Programmable——

智能盘点钢筋数量AI识别

【组成原理 六 存储器类型】

2022精选最新金融银行面试真题——附带答案

Lecture 2 Software Life Cycle

亿流量大考(3):不加机器,如何抗住每天百亿级高并发流量?

湖仓一体电商项目(五):内网穿透工具-网云穿

【游戏建模模型制作全流程】在ZBrush中雕刻恶魔城男性角色模型

论文解读(PPNP)《Predict then Propagate: Graph Neural Networks meet Personalized PageRank》

祝福一路顺风
随机推荐
【3D建模制作技巧分享】ZBrush模型制作流程:地精
As hot as ever, reborn | ISC2022 HackingClub White Hat Summit was successfully held!
One trick to cure pycharm DEBUG error UnicodeDecodeError: 'utf-8' codec can't decode
直播带货为农产品开拓销售渠道
go语言的time包介绍
JVM memory configuration parameter GC log
【游戏建模模型制作全流程】ZBrush蜥蜴模型雕刻教程
golang打开文件和读写文件
SQL Server 调用 WebService
ES 数据聚合、数据同步、集群
the warmest home
后排乘客不系安全带?事故瞬间被甩出
特征工程资料汇总
【2020】【论文笔记】超表面:多功能和可编程——
Ts——项目实战应用enum枚举
PowerBI scripture series
DREAMWEAVER8 部分问题解决方案
SSM整合完整流程讲解
期货开户哪个平台好,要正规安全的
生成回文数