1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-28 21:32:20 +00:00

修改generator

This commit is contained in:
Ruan Yifeng 2015-02-16 18:47:46 +08:00
parent 4ee9fa07d9
commit caacc57d9f

View File

@ -754,9 +754,12 @@ function* longRunningTask() {
scheduler(longRunningTask());
function scheduler(task) {
setTimeout(function () {
if (!task.next(task.value).done) {
scheduler(task);
setTimeout(function() {
var taskObj = task.next(task.value);
// 如果Generator函数未结束就继续调用
if (!taskObj.done) {
task.value = taskObj.value
scheduler(task);
}
}, 0);
}