Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the relationship between resolved and fulfilled in Promise

Shulou Source: shulou.com Published: 2022-06-03 11:02:12 11月15日 Update

This article will explain in detail about the relationship between resolved and fulfilled in Promise. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Fulfilled's understanding:

   I know that the Promise constructor accepts a function as an argument, and the function can take two arguments (also methods, provided by the js engine) resolve,reject, meaning "solve" and "reject, discard", respectively. Literally, it is easy to understand that these two methods are used to transform the state of Promise from pending to fulfilled and rejected.

     pending- > resolve method-> fulfilled

     pending- > reject method-> rejected

   from this can see my understanding is that those who say what resolved is fulfilled state, from the English grammar resolved is the past tense of resolve, that is to say, "solved", that means that the solution is successful, so according to the above process is also the state of fulfilled, then resolved and fulfilled are in the same state.

But    feels untenable from another point of view, because if it is solved, must it be successful? Think a little ('.')

Some paragraphs of the promise chapter fulfilled

   clearly knows from this discourse that the resolved referred to by Ruan Shen is also my trouble. what he said here can clearly see that resolved temporarily refers to the fulfilled state. if it is not this article, what if in the actual process, resolved does not necessarily mean that the state has changed to the fulfilled state, but there will be other possibilities, such as changing to the rejected state?!

Next, callback functions such as catch,then return the Promise of resolve.

  , then please allow me once again to quote the original sentence from Ruan God's promise.all:

In the above code, promises is an array of six Promise instances, and the callback function following the Promise.all method will be called only if the state of all six instances changes to fulfilled, or one of them becomes rejected.

   so only if the stateful state changes to fulfilled can the callback function after all be executed!

The picture above in    is actually described as follows: when the promise in all has its own catch method, when the promise becomes rejected, it triggers the catch method of its own promise, but not the catch method of promise that follows outside the all method.

The reason for    is simple: after the callback of the sub-catch method, it returns another promise in resolved state, so the final accepted children are all in resolved state.

This is the end of the article on "what is the relationship between resolved and fulfilled in Promise". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: State method that is function two article obvious success parameter only instance more if good practical untenable figure above code representative content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Redmi Huawei Shulou Information Microsoft