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
7171To 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```
9593function 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);
You can’t perform that action at this time.
0 commit comments