当前位置:网站首页>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
边栏推荐
- [PROJECT] small hat takeout (8)
- Mock test using postman
- Sub database and sub table & shardingsphere
- PyMySQL
- MySQL master-slave replication
- 文件操作《二》(5000字总结篇)
- Dlib of face recognition framework
- 扫码登录的原理你真的了解吗?
- Do you really understand the principle of code scanning login?
- Dancenn: overview of byte self-developed 100 billion scale file metadata storage system
猜你喜欢
Knowledge points and examples of [seven input / output systems]
自定义my_strcpy与库strcpy【模拟实现字符串相关函数】
如何建立 TikTok用户信任并拉动粉丝增长
groutine
Detailed explanation of Niuke - Gloves
TypeError: set_ figure_ params() got an unexpected keyword argument ‘figsize‘
扫码登录的原理你真的了解吗?
Feign report 400 processing
Construction of promtail + Loki + grafana log monitoring system
Shell脚本——Shell编程规范及变量
随机推荐
STM32__ 03 - beginner timer
freeCodeCamp----shape_ Calculator exercise
Zhongang Mining: Fluorite Flotation Process
如何用Redis实现分布式锁?
Deepinv20 installation MariaDB
Expression "func" tSource, object "to expression" func "tSource, object" []
Freecodecamp ---- budget & category exercise
◰ GL shadow map core steps
Interface document yaml
oracle 中快速获取表的列名列表
How much do you know about the process of the interview
Blue Bridge Cup provincial road 06 -- the second game of the 12th provincial competition
freeCodeCamp----prob_ Calculator exercise
杂文 谈谈古典的《拆掉思维里的墙》
VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN
MySQL master-slave replication
Log4j output log information to file
Lock lock
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
AIOT产业技术全景结构-数字化架构设计(8)