Promise

Promise:

This is a big pity (which is Pending), which must be Fulfilled (Fulfilled) and Rejected (failed).

Basic use of promise:

new Promise((resolve,reject)=>{... }) .then(success=>{... }) .catch(error=>{... }) .finally(()=>{... }); Promise.resolve(); Promise.reject(); Promise.all(); Promise.race();Copy the code

Promises:

1. The error callback in THEN (SUCCESS =>{},error=>{}) catches reject, but not the exception in the SUCCESS callback, so we recommend using catch() to catch reject

Return the new promise object in the call chain of then ().then () causes the order of execution to change, for example:

const p1 = new Promise((resolve, reject) => { console.log('promise1'); //1 resolve(); }) .then(() => { console.log('then11'); //3 new Promise((resolve, reject) => { console.log('promise2'); //4 resolve(); }) .then(() => { console.log('then21'); //6 }) .then(() => { console.log('then23'); / / 8}); }) .then(() => { console.log('then12'); / / 7}); const p2 = new Promise((resolve, reject) => { console.log('promise3'); //2 resolve(); }).then(() => { console.log('then31'); / / 5}); const p1 = new Promise((resolve, reject) => { console.log('promise1'); // 1 resolve(); }) .then(() => { console.log('then11'); // 2 return new Promise((resolve, reject) => { console.log('promise2'); // 3 resolve(); }) .then(() => { console.log('then21'); // 4 }) .then(() => { console.log('then23'); / / 5}); }) .then(() => { console.log('then12'); / / 6});Copy the code

3. Promise.then () The expected argument is a function. If it is not a function, value pass-through will occur. Even if passthrough occurs, the code in promise.then() will still execute.

Reference:

Start with a Promise interview question that keeps me up at night and dive into the Promise implementation details

Promise. How do you make a Promise

Promise.allsettled, how to implement a promise.allsettled

How do you control the number of concurrent promises you execute

This time, understand the Promise principle once and for all

Interviewer: “Can you make a Promise by hand?”

Take down asynchronous together

Did you really master promise?

45 Promise interview questions

Take a look at the most fully written implementation of ES6 Promise

Promise implementation principle (source code attached)

Interview selection Promise

Promise won’t…? Look here!! The most accessible Promise ever!!

The front end engineer must know the Promise implementation

Thoroughly understand the Promise principle and fully functional implementation

Promise was played 48 “tricks,” in-depth parsing of 10 commonly used modules

——————————————————————————-

【 例 】 Async /await shall know and await

Promises: Promises and Why Async/Await Wins in the end

How to avoid async/await hell

Once you know async/await, solve callback hell

Handwriting async, await, generator core logic

Hey, stop writing so many tries/catches to async functions

How to handle async await exception

Interviewer: Tell me what you understand about Async

Async principle analysis

7 pictures, 20 minutes async/await principle!

———————————————————————————–

As a front end, you need to know RxJS (Responsive Programming-streaming)

RxJS tutorial

RxJS source code parsing (5) — Operator III

RxJS – give you silky smooth programming experience (long, recommended collection)