当前位置:网站首页>[JS advanced] promise explanation
[JS advanced] promise explanation
2022-07-01 12:13:00 【Wangzai liunai】
Back to hell
promise promise
Fulfill your promise Promises sink into the sea Promise to wait for the result ……
resolve solve the problem
reject Refuse to consider
pending Wait for
A means to solve asynchronous process .
Promise It's a constructor need new
Promise Parameters excutor actuator
excutor -> resolve reject function
excutor new Promise call
// excutor It's synchronous
let promise = new Promise((resolve,reject)=>{
console.log(1);
})
console.log(2);
// then Is an asynchronous call excutor It's synchronous .
then Is an asynchronous call .
pending -> resolve
pending -> reject
Only in this way .
Promise.all([promise1,promise2,promise3])
Multiple asynchronous tasks run concurrently , Its results are used after creating commitments , Wait for all task results to be completed .
iterable The internal elements pass promise A collection of objects , If not promise, direct resolve Return the value to
iterable There are no elements inside , Just return an empty array .
Just one of them promise yes rejected In terms of state , Then the instance callback is rejected.
The reason for the failure is the first one promise Result
Promise.race()
Whoever finishes first will return to that promise Result , Success or failure (fullfilled perhaps rejected)
Test the response speed of resources or interfaces
async await
await Is an operator , Waiting for one Promise The operation means for the object to produce results
Function is pause async Execution of a function , wait for promise The result of the treatment .
If Promise The result is rejected, It throws an exception
acync Functions are implicit Promise return pending state
async It means that the current asynchronous function and the program under the same scope are asynchronous .
边栏推荐
- [106] 360 check font - check whether the copyright of local Fonts is commercially available
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8
- Onenet Internet of things platform - the console sends commands to mqtt product devices
- 消息队列之监控退款任务批处理过程
- MQ prevent message loss and repeated consumption
- Leetcode (Sword finger offer) - 58 - ii Rotate string left
- NOV Schedule for . Net to display and organize appointments and recurring events
- Acly and metabolic diseases
- [shell programming] - shell introductory learning
- MQ-防止消息丢失及重复消费
猜你喜欢

Binary stack (I) - principle and C implementation

Leetcode force buckle (Sword finger offer 31-35) 31 Stack push pop-up sequence 32i II. 3. Print binary tree from top to bottom 33 Post order traversal sequence 34 of binary search tree The path with a

Message queue monitoring refund task batch process
![[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn](/img/f2/7931952b832e84d7b8f2615906f33f.png)
[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn

91. (chapitre Cesium) simulation de lancement de fusées cesium

Use of easyexcel

Computer graduation project asp Net attendance management system vs developing SQLSERVER database web structure c programming computer web page source code project

Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS

Technology sharing | MySQL: how about copying half a transaction from the database?

LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
随机推荐
Machine learning - Data Science Library Day 3 - Notes
The Missing Semester
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3
对于mvvm和mvc的理解
我在中山,到哪里开户比较好?实际上网上开户安全么?
用实际例子详细探究OpenCV的轮廓检测函数findContours(),彻底搞清每个参数、每种模式的真正作用与含义
自定义 grpc 插件
LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
比特熊直播间一周年,英雄集结令!邀你来合影!
Leetcode force buckle (Sword finger offer 31-35) 31 Stack push pop-up sequence 32i II. 3. Print binary tree from top to bottom 33 Post order traversal sequence 34 of binary search tree The path with a
队列的链式存储
Chen Gong: Micro service, is it still so pure?
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
Onenet Internet of things platform - mqtt product devices send messages to message queues MQ
谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
Comment Nike a - t - il dominé la première place toute l'année? Voici les derniers résultats financiers.
91.(cesium篇)cesium火箭發射模擬
2022-06-28-06-29
C#依赖注入(直白明了)讲解 一看就会系列