Get the App
SLTechnology News&Howtos  ›  Development  › 

Limitation description and example usage of promise in javascript

Shulou Source: shulou.com Published: 2022-06-03 17:31:06 10月17日 Update

This article mainly explains "the limitation explanation and example usage of promise in javascript". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the limited explanation and example usage of promise in javascript".

Limitation description

1. Promise has a limitation that it cannot stop the promise chain.

2. When an error occurs in a link in the promise chain, it is not necessary to continue to execute downward, but promise does not provide the original way to cancel.

We can see that even if an exception is thrown, the promise chain does not stop. Although we can use promise that returns the pending state to pause the promise chain.

Example

Const promise1 = new Promise ((resolve) = > {setTimeout (()) = > {resolve ('hello');}, 1000);}); promise1.then ((value) = > {throw new Error (' wrong!');}) .then (value = > {console.log (value);}, error= > {console.log (error.message); return result;}) .then () {console.log ('DJL's');}) At this point, I believe that you have a deeper understanding of the "limitation explanation and example usage of promise in javascript". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Examples content learning original practical deeper necessary interesting practical practical that is limitations simple operation methods methods more friends status links websites Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info Huawei Xiaomi Apple