当前位置:网站首页>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)
// })
边栏推荐
猜你喜欢
随机推荐
torch单机多卡和多机多卡训练
Redis understanding
三个多月、40余场面试浓缩为6000字
DREAMWEAVER8 part of the problem solution
【游戏建模模型制作全流程】在ZBrush中雕刻恶魔城男性角色模型
【无标题】
2022年全网最全接口自动化测试框架搭建,没有之一
现在学习次世代3D游戏建模还能找到高薪好工作吗
PowerBI scripture series
Based on the results of the facts
Use ngrok to optimize web pages on raspberry pi (1)
2022七夕程序员必备的表白黑科技(七夕限定款)
idea 仓库地址连接不上问题
质量管理大师爱德华·戴明博士经典的质量管理14条原则
Lecture 2 Software Life Cycle
Ts——项目实战应用enum枚举
地面高度检测/平面提取与检测(Fast Plane Extraction in Organized Point Clouds Using Agglomerative Hierarchical Clu)
360市值四年蒸发3900亿,政企安全能救命吗?
轮播图动态渲染
【组成原理 六 存储器类型】









