function log(arg) {
$('<div>').text(arg).appendTo('body');
}
function run(gen) {
step();
function step(value) {
var result = gen.next(value);
if (result.value instanceof Promise) {
result.value.then(step);
}
}
}
function *program() {
var rand;
rand = yield getRandAsync();
log('first time around = ' + rand);
rand = yield getRandAsync();
log('second time around = ' + rand);
}
function getRandAsync() {
return Promise.resolve(Math.random());
}
run(program());