长生不老药睡眠/等待1秒

Elixir Sleep / Wait for 1 Second

如何休眠/等一秒?

我能找到的最好的东西是这样的(在 iex 中):

IO.puts "foo" ; :timer.sleep(1); IO.puts "bar"

但是我的两个看跌期权都没有延迟。

计时器使用毫秒而不是秒,更新为:

IO.puts "foo" ; :timer.sleep(1000); IO.puts "bar"

Erlang 文档中 :timer 的文档:

Suspends the process calling this function for Time amount of milliseconds and then returns ok, or suspend the process forever if Time is the atom infinity. Naturally, this function does not return immediately.

http://erlang.org/doc/man/timer.html#sleep-1

从 Elixir 1.3 开始你可以使用 Process.sleep/1:

Process.sleep(1000)

参数以毫秒为单位。