Skip to content

Commit 16f166a

Browse files
committed
Fixing example code
1 parent 417c38a commit 16f166a

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

control-flow/index.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,10 @@ This might be reasonable in simple situations but it's easy for callbacks to get
7171
To show many responses, consider the following code. If we ran them beside each other, the output would not be reliable.
7272

7373
```
74-
function randomDelayedResponse(text) {
75-
// Using a timeout here for the sake of simulating an external request
74+
function randomDelayedResponse(text, callback) {
7675
const timeOut = Math.floor(Math.random() * 100) + 1;
77-
const output = text;
7876
setTimeout(() => {
79-
return output;
77+
callback(text);
8078
}, timeOut);
8179
}
8280
@@ -93,7 +91,6 @@ While the code does run in order and run the `randomDelayedResponse` function wi
9391

9492
```
9593
function randomDelayedResponse(text, callback) {
96-
// Using a timeout here for the sake of simulating an external request
9794
const timeOut = Math.floor(Math.random() * 100) + 1;
9895
setTimeout(() => {
9996
callback(text);

0 commit comments

Comments
 (0)