You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/11-async/02-promise-basics/article.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,9 +60,9 @@ We can see two things by running the code above:
60
60
1. The executor is called automatically and immediately (by `new Promise`).
61
61
2. The executor receives two arguments: `resolve` and `reject` — these functions are pre-defined by the JavaScript engine. So we don't need to create them. We only should call one of them when ready.
62
62
63
-
After one second of "processing" the executor calls `resolve("done")` to produce the result:
63
+
After one second of "processing" the executor calls `resolve("done")` to produce the result. This changes the state of the `promise` object:
64
64
65
-

65
+

66
66
67
67
That was an example of a successful job completion, a "fulfilled promise".
68
68
@@ -75,14 +75,16 @@ let promise = new Promise(function(resolve, reject) {
75
75
});
76
76
```
77
77
78
+
The call to `reject(...)` moves the promise object to `"rejected"` state:
79
+
78
80

79
81
80
-
To summarize, the executor should do a job (something that takes time usually) and then call `resolve` or `reject` to change the state of the corresponding Promise object.
82
+
To summarize, the executor should do a job (something that takes time usually) and then call `resolve` or `reject` to change the state of the corresponding promise object.
81
83
82
-
The Promise that is either resolved or rejected is called "settled", as opposed to a initially "pending" Promise.
84
+
A promise that is either resolved or rejected is called "settled", as opposed to a initially "pending" promise.
83
85
84
86
````smart header="There can be only a single result or an error"
85
-
The executor should call only one `resolve` or one `reject`. The promise's state change is final.
87
+
The executor should call only one `resolve` or one `reject`. Any state change is final.
86
88
87
89
All further calls of `resolve` and `reject` are ignored:
0 commit comments