Semanticize intermediate headings

This commit is contained in:
Chalarangelo
2020-09-29 19:22:26 +03:00
parent 13627134a6
commit 0007611b19
35 changed files with 125 additions and 126 deletions

View File

@ -7,13 +7,13 @@ cover: blog_images/green-plant.jpg
excerpt: Learn everything you need to know about promises and asynchronous JavaScript with this handy cheatsheet.
---
**Promise basics**
### Promise basics
- **Promises** start in a **pending state**, neither fullfiled or rejected.
- When the operation is completed, a promise will become **fullfiled with a value**.
- If the operation fails, a promise will get **rejected with an error**.
**Creating promises**
### Creating promises
- The function passed to a `new Promise` will execute synchronously.
- Use `resolve()` or `reject()` to create promises from values.
@ -34,7 +34,7 @@ new Promise((resolve, reject) => {
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
```
**Handling promises**
### Handling promises
- `Promise.prototype.then()` accepts two optional arguments (`onFulfilled`, `onRejected`).
- `Promise.prototype.then()` will call `onFulfilled` once the promise is fulfilled.
@ -68,7 +68,7 @@ promisedOperation()
- All three of the above methods will not be executed at least until the next tick, even for promises that already have an outcome.
**Combining promises**
### Combining promises
- `Promise.all()` turns an array of promises into a promise of an array.
- If any promise is rejected, the error will pass through.
@ -89,7 +89,7 @@ Promise
});
```
**async/await**
### async/await
- Calling an `async` function always results in a promise.
- `(async () => value)()` will resolve to `value`.