Last active
August 29, 2015 14:04
-
-
Save jitomesky/2648250b9020d62beee7 to your computer and use it in GitHub Desktop.
JavaScript用Delay関数。BoneScriptとあわせてどうぞ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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