|
3 | 3 |
|
4 | 4 | `Promise.all` is a great way to parallelize multiple operations. It's especially useful when we need to make parallel requests to multiple services. |
5 | 5 |
|
6 | | -However, there's a hidden danger. Hopefully we'll be able to identify its cause. |
| 6 | +However, there's a hidden danger. We'll see an example in this task and explore how to avoid it. |
7 | 7 |
|
8 | 8 | Let's say we have a connection to a remote service, such as a database. |
9 | 9 |
|
@@ -39,7 +39,7 @@ function disconnect() { |
39 | 39 |
|
40 | 40 | Now here's the problem. |
41 | 41 |
|
42 | | -We write a simple code to connect and send 3 queries in parallel (all of them take different time, e.g. 100, 200 and 300ms), then disconnect: |
| 42 | +We wrote the code to connect and send 3 queries in parallel (all of them take different time, e.g. 100, 200 and 300ms), then disconnect: |
43 | 43 |
|
44 | 44 | ```js |
45 | 45 | // Helper function to call async function fn after ms milliseconds |
@@ -69,8 +69,8 @@ async function run() { |
69 | 69 | run(); |
70 | 70 | ``` |
71 | 71 |
|
72 | | -Two of these queries are (by chance) unsuccessful, but we're smart enough to wrap the `Promise.all` call into a `try...catch` block. |
| 72 | +Two of these queries are (by chance) unsuccessful, but we handle it by wrapping the `Promise.all` call into a `try..catch` block. |
73 | 73 |
|
74 | | -However, this script actually leads to an uncaught error in console! |
| 74 | +However, this doesn't help! This script actually leads to an uncaught error in console! |
75 | 75 |
|
76 | 76 | Why? How to avoid it? |
0 commit comments