Skip to content

Instantly share code, notes, and snippets.

@gskachkov
Last active July 25, 2017 10:50
Show Gist options
  • Save gskachkov/611206af09adbcd4adae821d02bc7f8e to your computer and use it in GitHub Desktop.
Save gskachkov/611206af09adbcd4adae821d02bc7f8e to your computer and use it in GitHub Desktop.
const getValue = () => { console.log('get-value'); return 'value'; };
async function* foo(value = getValue()) {
console.log('before yield', value);
yield value + '-yiled';
console.log('after yield');
return value + '-result';
}
async function boo() {
const iter = foo();
console.log('before iteration');
let result = await iter.next();
console.log('step1:', result.value, result.done);
result = await iter.next();
console.log('step2:', result.value, result.done);
}
boo();
// get-value
// before iteration
// before yield value
// step1: value-yiled false
// after yield
// step2: value-result true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment