風雲 (ID: 2)
等级:骑士
积分:18
发帖:1 篇
来自:保密
注册:2024-05-04 22:54:28
造访:2024-05-31 14:19:41
发帖:1 篇
来自:保密
注册:2024-05-04 22:54:28
造访:2024-05-31 14:19:41
<script type="text/javascript">
function co(gen, func) {
if(!func) return new Promise(ok => co(gen, ok));
var run = function(arg) {
var g = gen.next(arg), v = g.value;
g.done ? func(v) : v(run);
}; run();
}
function* test() {
yield ok => setTimeout(ok, 1000);
document.write("Started");
yield ok => setTimeout(ok, 1000);
document.body.innerHTML += "<br />Ended";
yield ok => setTimeout(ok, 10);
return "Over";
};
co(test()).then(alert);
</script>