JavaScript/sleep:修订间差异
来自康健生活
| 第71行: | 第71行: | ||
== co == | == co == | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
function sleep(ms) { | |||
return function (cb) { | |||
setTimeout(cb, ms); | |||
} | |||
} | |||
co(function *() { | |||
var now = Date.now(); | |||
yield sleep(2000); | |||
expect(Date.now() - now).to.not.be.below(2000); | |||
}); | |||
</syntaxhighlight> | </syntaxhighlight> | ||