Search code examples
ocamldelaysleepwaitthread-sleep

Sleeping less than a second in OCaml


The Unix.sleep function can suspend the program for whole seconds, but how can you suspend it for less than a second?


Solution

  • The classical Unix solution for this is to use select() with no file descriptors:

    let minisleep (sec: float) =
        ignore (Unix.select [] [] [] sec)