File tree Expand file tree Collapse file tree 1 file changed +2
-5
lines changed Expand file tree Collapse file tree 1 file changed +2
-5
lines changed Original file line number Diff line number Diff line change @@ -71,12 +71,10 @@ This might be reasonable in simple situations but it's easy for callbacks to get
71
71
To show many responses, consider the following code. If we ran them beside each other, the output would not be reliable.
72
72
73
73
```
74
- function randomDelayedResponse(text) {
75
- // Using a timeout here for the sake of simulating an external request
74
+ function randomDelayedResponse(text, callback) {
76
75
const timeOut = Math.floor(Math.random() * 100) + 1;
77
- const output = text;
78
76
setTimeout(() => {
79
- return output ;
77
+ callback(text) ;
80
78
}, timeOut);
81
79
}
82
80
@@ -93,7 +91,6 @@ While the code does run in order and run the `randomDelayedResponse` function wi
93
91
94
92
```
95
93
function randomDelayedResponse(text, callback) {
96
- // Using a timeout here for the sake of simulating an external request
97
94
const timeOut = Math.floor(Math.random() * 100) + 1;
98
95
setTimeout(() => {
99
96
callback(text);
You can’t perform that action at this time.
0 commit comments