Created
February 12, 2019 05:43
-
-
Save yokotak0527/048803af915ec91e153c2d730e9cb9fc to your computer and use it in GitHub Desktop.
ジェネレータ関数を使った直接非同期通信
This file contains 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
// ジェネレータ関数 | |
const gfn = function * (start, end) { | |
while(start <= end) { | |
yield [expect Promise code] | |
start++ | |
} | |
} | |
const g = gfn(1, 10) | |
const loaded = () => { | |
const result = g.next(); | |
if (_result.done) { | |
console.log('complete') | |
} else { | |
_result.value.then(data => loaded()) | |
} | |
loaded() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment