JavaScript/sleep:修订间差异
来自康健生活
| 第23行: | 第23行: | ||
// ... | // ... | ||
})</syntaxhighlight> | })</syntaxhighlight> | ||
{{leftrightflex|<syntaxhighlight lang="javascript"> | |||
function* sleep(ms){ | |||
yield new Promise(function(resolve,reject){ | |||
console.log('mark~'); | |||
setTimeout(resolve,ms); | |||
}) | |||
} | |||
sleep(500).next().value.then(()=>{ | |||
console.log('mark,end~'); | |||
})</syntaxhighlight>|{{consoleout|<pre> | |||
</pre>}}}} | |||
同步执行 | 同步执行 | ||