当前位置:网站首页>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)
// })
边栏推荐
- 测试薪资这么高?刚毕业20K,仅需3.5个月
- promise详解
- 剑指Offer | 数值的整数次方
- 移动web开发03
- 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
- Use ngrok to optimize web pages on raspberry pi (1)
- 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
- Leaflets of three bouquet of roses
- golang打开文件和读写文件
猜你喜欢

【3D建模制作技巧分享】ZBrush如何使用Z球

If you can't get your heart, use "distributed lock" to lock your people

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

剑指 Offer | 03. 数组中重复的数字

【3D建模制作技巧分享】如何使用ZBrush导出效果图

Reconfigure the ffmpeg plugin in chrome

【字符串函数内功修炼】strncpy + strncat + strncmp(二)

赶紧进来!!!教你C语言实现扫雷小游戏(文章最后有源码!!!)

Latex快速插入作者ORCID

FinClip崁入式搭建生态平台,降低合作门槛
随机推荐
软件测试技术之如何编写测试用例(4)
typeScript-闭包函数的使用
直播带货为农产品开拓销售渠道
湖仓一体电商项目(五):内网穿透工具-网云穿
各行各业都受到重创,游戏行业却如火如荼,如何加入游戏模型师职业
MySQL的JSON 数据类型2
【游戏建模模型制作全流程】使用ZBrush制作骷髅王
Using ngrok to optimize web pages on raspberry pi (2)
亿流量大考(3):不加机器,如何抗住每天百亿级高并发流量?
Debian防火墙的开关以及状态
Acwing3593. 统计单词
JVM memory configuration parameter GC log
360市值四年蒸发3900亿,政企安全能救命吗?
三个多月、40余场面试浓缩为6000字
One trick to cure pycharm DEBUG error UnicodeDecodeError: 'utf-8' codec can't decode
SQL Server 调用 WebService
剑指Offer | 数值的整数次方
【3D建模制作技巧分享】Maya模型如何导入zbrush
Linux系统重启和停止Mysql服务教程
the warmest home