ES6: What is Promise?

1, promise of origin

     Before, when we deal with asynchronous network requests, often using such wording:

image

And then a bit more complex, we need to finish after the first request api, go to request the second interface, then the way things turned out:

image

Based on this, in the case of increased demand, we are likely to face a disastrous arrival - callback hell.

image

The consequences are:

1, bloated code is complex, unreadable

2, coupling is too high, it is difficult to maintain the late

3, poor reusability of code, make the code more bloated in disguise

4, easy to breed bug, but also handle exceptions in the callback

At this time, how to solve this problem? We hope that the code can be written in a more friendly way, promise resulting specification was born.

2. What is the promise

Asynchronous programming is a promise of a solution. Currently the industry a settlement callback hell are Q and bluebird.

image

Guess you like

Origin www.cnblogs.com/hxw1024/p/12088403.html
Recommended