Skip to content

Commit 41e2fb0

Browse files
authored
1 parent 6b16391 commit 41e2fb0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -972,13 +972,13 @@ const xFetcherPromise = new Promise( // Create promise using "new" keyword and s
972972
)
973973
```
974974

975-
As seen in the above sample, the Promise object takes a function which takes two parameters **resolve** and **reject**. Those parameters are functions which when called are going to move the promise *pending* state to respectively a *fulfilled* and *rejected* state.
975+
As seen in the above sample, the Promise object takes an *executor* function which takes two parameters **resolve** and **reject**. Those parameters are functions which when called are going to move the promise *pending* state to respectively a *fulfilled* and *rejected* state.
976976

977-
But at the moment, the promise has not been used but only has been declared and stored into *xFetcherPromise* variable! So it doesn't have a current state.
977+
The promise is in pending state after instance creation and it's *executor* function is executed immediately. Once one of the function *resolve* or *reject* is called in the *executor* function, the promise will call its associated handlers.
978978

979-
##### Use the promise
979+
##### Promise handlers usage
980980

981-
To use the promise, we do the following:
981+
To get the promise result (or error), we must attach to it handlers by doing the following:
982982

983983
```js
984984
xFetcherPromise
@@ -990,11 +990,11 @@ xFetcherPromise
990990
})
991991
```
992992

993-
```.then``` is a method that once called will put the xFetcherPromise in **pending** state. When called, the promise body runs, and in this case, an Ajax call is being done.
993+
If the promise succeeds, *resolve* is executed and the function passed as ```.then``` parameter is executed.
994994

995-
If it succeeds, *resolve* is called and the function passed as ```.then``` parameter is executed.
995+
If it fails, *reject* is executed and the function passed as ```.catch``` parameter is executed.
996996

997-
If it fails, *reject* is called and the function passed as ```.catch``` parameter is executed.
997+
> **Note :** If the promise has already been fulfilled or rejected when a corresponding handler is attached, the handler will be called, so there is no race condition between an asynchronous operation completing and its handlers being attached. [(Ref: MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Description)
998998
999999
#### External Resources
10001000

0 commit comments

Comments
 (0)