我有以下示例:
var first=setInterval(function() {
var t=new Date();
console.log("Started: ",t);
sleep(function(){
var t=new Date();
console.log("Finished: ",t);
});
},500);
function sleep(callback){
for (var i=0;i<10000000000;i++){
//waiting
}
callback();
}
恕我直言 sleep 应该异步执行,但它不会输出:
Started: Mon Mar 04 2013 12:31:10 GMT+0200 (EET)
Finished: Mon Mar 04 2013 12:31:23 GMT+0200 (EET)
Started: Mon Mar 04 2013 12:31:24 GMT+0200 (EET)
Finished: Mon Mar 04 2013 12:31:36 GMT+0200 (EET)
Started: Mon Mar 04 2013 12:31:36 GMT+0200 (EET)