Last active
August 29, 2015 14:15
-
-
Save sue445/2c658c936e5aa9d9a7d4 to your computer and use it in GitHub Desktop.
sleepで指定した秒数だけsleepされるわけではない
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
irb(main):001:0> ret = sleep 0.1 | |
#=> 0 | |
irb(main):002:0> ret = sleep 1.5 | |
#=> 2 |
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
EXISTS_USLEEP = `which usleep`.length > 0 | |
def usleep(sec) | |
return if sec == 0 | |
if EXISTS_USLEEP | |
msec = sec * 1000000 | |
system "usleep #{msec.to_i}" | |
else | |
# usleepが無い場合は普通のsleep | |
sleep sec | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment