Skip to content

Instantly share code, notes, and snippets.

@yokotak0527
Created February 12, 2019 05:43
Show Gist options
  • Save yokotak0527/048803af915ec91e153c2d730e9cb9fc to your computer and use it in GitHub Desktop.
Save yokotak0527/048803af915ec91e153c2d730e9cb9fc to your computer and use it in GitHub Desktop.
ジェネレータ関数を使った直接非同期通信
// ジェネレータ関数
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