问题
The Unix.sleep
function can suspend the program for whole seconds, but how can you suspend it for less than a second?
回答1:
The classical Unix solution for this is to use select() with no file descriptors:
let minisleep (sec: float) =
ignore (Unix.select [] [] [] sec)
回答2:
The Thread.delay
function pauses the thread for the given number of seconds, but it takes a float, allowing you to pause the thread for less than a second.
回答3:
from Unix module
val sleepf : float -> unit
Stop execution for the given number of seconds. Like sleep, but fractions of seconds are supported.
来源:https://stackoverflow.com/questions/10789601/sleeping-less-than-a-second-in-ocaml