Created
May 18, 2020 15:38
-
-
Save kentac55/939ccec4e555863bd24d3a657a69c0ba to your computer and use it in GitHub Desktop.
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
| function timer() { | |
| return new Promise(resolve => setTimeout(_ => resolve(), 1000)) | |
| } | |
| async function* asyncGenerator(c) { | |
| var i = 0; | |
| while (i < c) { | |
| await timer() | |
| yield i++; | |
| } | |
| } | |
| (async function() { | |
| for await (num of asyncGenerator(3)) { | |
| console.log(num); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment