当前位置:网站首页>Promise -- several key problems
Promise -- several key problems
2022-04-21 13:41:00 【monstkl】
One 、 How to change promise The state of
1、 call resolve, The status changes to resolved
2、 call reject, The status changes to rejected
3、throw, The status changes to rejected
Two 、promise More than one success was specified / Failed callback function , Whether it will call
promise On the implementation , Will save multiple callback functions , That is, it will call
// The same promise p, When its state changes to resolved after ,1 and 2 They all print
p.then(
value=> {
console.log(1)
},
reason=> {
}
)
p.then(
value=> {
console.log(2)
},
reason=> {
}
)
3、 ... and 、 change promise Status and specified callback function , Whoever first after ?
Fine , such promise Asynchronous processing is more flexible to use
// The code in the body of the executor function is synchronized
//1、 Change the state first , Specify callback after
new Promise((resolve,reject)=>{
resolve(1)
}).then(
value=>{},
reason=>{},
)
//2、 Specify callback first , Post change state
new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve(1)
},1000)
}).then(
value=>{},
reason=>{},
)
Four 、promise.then() Back to the new promise What determines the outcome status of ?
1、 Put it simply : from then() Callback function executed in , The results of the implementation determine
2、 Detailed description :
a、 Throw an exception , new promise Turn into rejected The state of ,reason Exception thrown for
b、 If yes or no is returned promise, new promise Turn into resolved state ,value by return Value
c、 If you return a promise, this promise The result will be new promise Result
5、 ... and 、promise Abnormal transmission of
p.then(
value=>{},
// There are no failed callbacks written here , The following code will be automatically added
//reason=>{throw reason} perhaps reason=> Promise.reject(reason)
).then(
value=>{},
// There are no failed callbacks written here , The following code will be automatically added
//reason=>{throw reason} perhaps reason=> Promise.reject(reason)
).catch(
reason=>{}
)
1、promise Abnormal transmission refers to , When using promise Of then Chain call , Even if not in then Failed callback function specified in , You can also specify the failed callback at the end , Use catch.
2、 Exception in any previous operation , Not handled halfway , Will reach the last catch in
6、 ... and 、 How to interrupt promise Chain call of
1、 Need to know :catch Then you can continue then
p.catch(
reason=>{}
).then(
value=>{},
reason=>{},
)
2、 How to operate , interrupt promise Chain call of
Returns a... In the body of the callback function being executed pending State of promise
return new Promise(()=>{})
版权声明
本文为[monstkl]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211339444245.html
边栏推荐
- 暴力匹配阈值的基准细胞检测方案
- LLVM之父Chris Lattner:编译器的黄金时代
- String count (convert to base)
- Number of effective triangles (double pointer (reverse scanning) + bisection)
- CV technical guide free knowledge planet
- npm---npm配置文件
- nmap使用
- sql数据库入门-what&MySQL&按照MySQL
- Peking University ACM problems 1009: edge detection
- 3-4Dom形XSS详解以及演示
猜你喜欢

Open mmlab / mmpose installation and use tutorial
![leetcode:513. Find the value in the lower left corner of the tree [simply BFS find the first one in each layer]](/img/be/d026b15f89f39944cf03aa0a05d9e3.png)
leetcode:513. Find the value in the lower left corner of the tree [simply BFS find the first one in each layer]

哈夫曼编码

Hcip road OSPF expansion configuration

Could not load dynamic library ‘libcusolver.so.11‘

实现随机标签,字体大小、颜色随机显示

Mysql 浅析行锁如何减少冲突提高性能
![Buuctf [Chapter 3 Advanced Web] logic vulnerability](/img/fb/99a5c60979970a9d6cd0fe0e0fb7a4.png)
Buuctf [Chapter 3 Advanced Web] logic vulnerability

Could not load dynamic library ‘libcusolver. so. 11‘

JDBC 驱动升级到 Version 8.0.28 连接 MySQL 的踩坑记录
随机推荐
[digital signal processing] correlation coefficient (concept of correlation coefficient | energy signal and power signal | causality of system)
制造业中小企业转型能力建设分享
MySQL学习笔记-day03
字符串 - 1. 字符串长度 (10 分)C语言标准函数库中包括 strlen 函数,用于计算字符串的长度。作为练习,我们自己编写一个功能与之相同的函数。
leetcode:824. Goat Latin [simple string manipulation]
专家系统实例及其骨架系统
Small and medium-sized manufacturing enterprises transformation capacity-building sharing
一级等保怎么做?要收费吗?等保要求是什么?
前馈神经网络
工具函数---小数位处理
SQLyog导入sql文件
二叉树创建及其线索化
Markdown语法及测试
Chapter 4 - hierarchical query of SQL query
[csnote] DB exception (redundant data, modification exception, deletion exception, insertion exception)
【栈和队列专题】—— 双队列模拟栈
npm---npm配置文件
单体测试使用Assert.assertThat(expected,Matcher matcher)来对比结果和预期
echart常见的配置项(线、区域、文本)
About ` object Thoughts on the impossibility of calling clone() ` subclass