Skip to content

Commit a558c9b

Browse files
committed
fix headings
1 parent 84a8969 commit a558c9b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

apps/site/pages/en/learn/asynchronous-work/discover-promises-in-nodejs.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ In this example, `fs.promises.readFile()` returns a Promise, which we handle usi
181181

182182
JavaScript's `Promise` global provides several powerful methods that help manage multiple asynchronous tasks more effectively:
183183

184-
### **`Promise.all()`**:
184+
### `Promise.all()`
185185

186186
This method accepts an array of Promises and returns a new Promise that resolves once all the Promises are fulfilled. If any Promise is rejected, `Promise.all()` will immediately reject. However, even if rejection occurs, the Promises continue to execute. When handling a large number of Promises, especially in batch processing, using this function can strain the system's memory.
187187

@@ -200,7 +200,7 @@ Promise.all([fetchData1, fetchData2])
200200
});
201201
```
202202

203-
### **`Promise.allSettled()`**:
203+
### `Promise.allSettled()`
204204

205205
This method waits for all promises to either resolve or reject and returns an array of objects that describe the outcome of each Promise.
206206

@@ -216,7 +216,7 @@ Promise.allSettled([promise1, promise2]).then(results => {
216216

217217
Unlike `Promise.all()`, `Promise.allSettled()` does not short-circuit on failure. It waits for all promises to settle, even if some reject. This provides better error handling for batch operations, where you may want to know the status of all tasks, regardless of failure.
218218

219-
### **`Promise.race()`**:
219+
### `Promise.race()`
220220

221221
This method resolves or rejects as soon as the first Promise settles, whether it resolves or rejects. Regardless of which promise settles first, all promises are fully executed.
222222

@@ -231,7 +231,7 @@ Promise.race([task1, task2]).then(result => {
231231
});
232232
```
233233

234-
### **`Promise.any()`**:
234+
### `Promise.any()`
235235

236236
This method resolves as soon as one of the Promises resolves. If all promises are rejected, it will reject with an `AggregateError`.
237237

@@ -251,7 +251,7 @@ Promise.any([api1, api2, api3])
251251
});
252252
```
253253

254-
### **`Promise.reject()` and `Promise.resolve()`**:
254+
### `Promise.reject()` and `Promise.resolve()`
255255

256256
These methods create a rejected or resolved Promise directly.
257257

@@ -261,7 +261,7 @@ Promise.resolve('Resolved immediately').then(result => {
261261
});
262262
```
263263

264-
### **`Promise.try()`**:
264+
### `Promise.try()`
265265

266266
`Promise.try()` is a method that executes a given function, whether it's synchronous or asynchronous, and wraps the result in a promise. If the function throws an error or returns a rejected promise, `Promise.try()` will return a rejected promise. If the function completes successfully, the returned promise will be fulfilled with its value.
267267

@@ -286,7 +286,7 @@ Promise.try(mightThrow)
286286

287287
In this example, `Promise.try()` ensures that if `mightThrow()` throws an error, it will be caught in the `.catch()` block, making it easier to handle both sync and async errors in one place.
288288

289-
### **`Promise.withResolvers()`**:
289+
### `Promise.withResolvers()`
290290

291291
This method creates a new promise along with its associated resolve and reject functions, and returns them in a convenient object. This is used, for example, when you need to create a promise but resolve or reject it later from outside the executor function.
292292

@@ -339,7 +339,7 @@ performTask();
339339

340340
In addition to Promises, Node.js provides several other mechanisms for scheduling tasks in the event loop.
341341

342-
### **`queueMicrotask()`**
342+
### `queueMicrotask()`
343343

344344
`queueMicrotask()` is used to schedule a microtask, which is a lightweight task that runs after the currently executing script but before any other I/O events or timers. Microtasks include tasks like Promise resolutions and other asynchronous operations that are prioritized over regular tasks.
345345

@@ -353,7 +353,7 @@ console.log('Synchronous task is executed');
353353

354354
In the above example, "Microtask is executed" will be logged after "Synchronous task is executed," but before any I/O operations like timers.
355355

356-
### **`process.nextTick()`**
356+
### `process.nextTick()`
357357

358358
`process.nextTick()` is used to schedule a callback to be executed immediately after the current operation completes. This is useful for situations where you want to ensure that a callback is executed as soon as possible, but still after the current execution context.
359359

@@ -365,7 +365,7 @@ process.nextTick(() => {
365365
console.log('Synchronous task executed');
366366
```
367367

368-
### **`setImmediate()`**:
368+
### `setImmediate()`
369369

370370
`setImmediate()` is used to execute a callback after the current event loop cycle finishes and all I/O events have been processed. This means that `setImmediate()` callbacks run after any I/O callbacks, but before timers.
371371

@@ -377,7 +377,7 @@ setImmediate(() => {
377377
console.log('Synchronous task executed');
378378
```
379379

380-
### **When to Use Each**:
380+
### When to Use Each
381381

382382
- Use `queueMicrotask()` for tasks that need to run immediately after the current script and before any I/O or timer callbacks, typically for Promise resolutions.
383383
- Use `process.nextTick()` for tasks that should execute before any I/O events, often useful for deferring operations or handling errors synchronously.

0 commit comments

Comments
 (0)