Can anyone please give me time explaining why
else
result=task.next(result.value);
console.log(result);
Not outputs 3
function run(taskDef) {
// create the iterator, make available elsewhere
let task = taskDef();
// start the task
let result = task.next();
console.log(result);
// recursive function to keep calling next()
function step() {
// if there's more to do
if (!result.done) {
console.log(typeof result.value);
if (typeof result.value === "function") {
result.value(function(err, data) {
if (err) {
result = task.throw(err);
return;
}
console.log(data);
result = task.next(data);
console.log(result);
step();
});
} else {
result = task.next(result.value);
console.log(result);
step();
}
}
}
// start the process
step();
}
run(function*() {
let value = yield ()=>{console.log("I am a function")};
yield 3;
});
function run(taskDef) {
// create the iterator, make available elsewhere
let task = taskDef();
console.log(1);
// start the task
let result = task.next();
console.log(result);
// recursive function to keep calling next()
function step() {
console.log(3);
// if there's more to do
if (!result.done) {
console.log(4);
console.log(typeof result.value);
if (typeof result.value === "function") {
console.log(5);
console.log(result)
result.value(function(err, data) {
console.log(6);
if (err) {
console.log(7);
result = task.throw(err);
return;
}
console.log(data);
result = task.next(data);
console.log(result);
console.log(8);
step();
});
} else {
console.log(9)
result = task.next(result.value);
console.log(result);
step();
}
}
}
console.log(2)
// start the process
step();
}
run(function*() {
let value = yield ()=>{console.log("I am a function")};
yield 3;
});
Hint: What’s the difference between that code and this one?
function run(taskDef) {
// create the iterator, make available elsewhere
let task = taskDef();
console.log(1);
// start the task
let result = task.next();
console.log(result);
// recursive function to keep calling next()
function step() {
console.log(3);
// if there's more to do
if (!result.done) {
console.log(4);
console.log(typeof result.value);
if (typeof result.value === "function") {
console.log(5);
console.log(result)
result.value("Boo");
} else {
console.log(9)
result = task.next(result.value);
console.log(result);
step();
}
}
}
console.log(2)
// start the process
step();
}
run(function*() {
let value = yield ()=>{console.log("I am a function")};
yield 3;
});