Sleeping less than a second in OCaml

拥有回忆 提交于 2020-01-01 08:17:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!