Skip to content

Instantly share code, notes, and snippets.

@jitomesky
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jitomesky/2648250b9020d62beee7 to your computer and use it in GitHub Desktop.
Save jitomesky/2648250b9020d62beee7 to your computer and use it in GitHub Desktop.
JavaScript用Delay関数。BoneScriptとあわせてどうぞ。
function delay(delay_ms){
var nowtime = Date.now();
var timeout = nowtime + delay_ms;
while(nowtime < timeout){
nowtime = Date.now();
}
}
// us待ちメソッド…ただし正確性は無い
function delayMicroseconds(delay_us){
var date = new Date();
var nowtime = date.getMilliseconds();
var timeout = nowtime + delay_us;
if(timeout > 999){
timeout -= 999;
while(nowtime > timeout){
var date = new Date();
nowtime = date.getMilliseconds();
}
}
else{
while(nowtime < timeout){
var date = new Date();
nowtime = date.getMilliseconds();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment