当前位置:网站首页>Promise (II)
Promise (II)
2022-04-23 16:59:00 【Endless cake】
Promise Use
<script>
// Create a new Promise
const p = new Promise((resolve, reject) => { // Actuator functions
// 2. Perform asynchronous operation tasks
// 3.1 If it works , call resolve(value)
// 3.2 If it works , call reject(reason)
setTimeout(() => {
const time = Date.now() // If the current time is even, it means success , Otherwise, it means failure
if (time % 2 == 0) { // success
resolve(' Success data ,time=' + time)
} else { // Failure
reject(' Failed data ,time=' + time)
}
}, 1000)
})
p.then(
value => { // Receive successful value data onResolved
console.log(' Successful callback ', value)
},
reason => { // Receive successful reason data ovRejected
console.log(' Failed callback ', reason)
}
)
</script>
版权声明
本文为[Endless cake]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554519722.html
边栏推荐
- VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN
- PostgreSQL列存与行存
- Talk about browser cache control
- Introduction to new functions of camtasia2022 software
- Document operation II (5000 word summary)
- Decimal format decimal / datetime conversion processing
- Solution architect's small bag - 5 types of architecture diagrams
- Camtasia2022软件新增功能介绍
- Kingdee Cloud Star API calling practice
- Copy constructor shallow copy and deep copy
猜你喜欢
Nifi fast installation and file synchronization
扫码登录的原理你真的了解吗?
1-1 NodeJS
Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)
NVIDIA graphics card driver error
TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
STM32__ 03 - beginner timer
Bytevcharts visual chart library, I have everything you want
【PIMF】OpenHarmony啃论文俱乐部—在ACM Survey闲逛是什么体验
随机推荐
New keyword learning and summary
Calculate pie chart percentage
AIOT产业技术全景结构-数字化架构设计(8)
About stream flow, write it down briefly------
MySQL master-slave replication
正则过滤内网地址和网段
∑GL-透视投影矩阵的推导
Get the column name list of the table quickly in Oracle
How to implement distributed locks with redis?
无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
Dlib of face recognition framework
RTKLIB 2.4.3源码笔记
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
◰ GL shader handler encapsulation
Copy constructor shallow copy and deep copy
Milvus 2.0 质量保障系统详解
Log4j output log information to file
Use case labeling mechanism of robot framework
Knowledge points and examples of [seven input / output systems]
Introduction to new functions of camtasia2022 software