Last active
June 16, 2016 01:11
-
-
Save mekdev/fbb6764a21b7cb7538b1 to your computer and use it in GitHub Desktop.
Javascript asynchronous
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var source = ['foo', 'bar', 'baz']; | |
| var result = []; | |
| setTimeout(function () { | |
| for (var i = 0 ; i < source.length ; i++) { | |
| console.log('Stepping through : ' + source[i]); | |
| result.push(source[i]); | |
| console.log('Current result: ' + result); | |
| } | |
| }, 1000); // Wait 1000 ms to finish operation | |
| console.log('Result: ' + result); | |
| console.log('Finished!!'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Result: | |
| Finished!! | |
| Stepping through : foo | |
| Current result: foo | |
| Stepping through : bar | |
| Current result: foo,bar | |
| Stepping through : baz | |
| Current result: foo,bar,baz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment