Logo

Programming-Idioms

History of Idiom 45 > diff from v38 to v39

Edit summary for version 39 by slashmili:
[Elixir] The previous code was using Erlang library, this new one is using Elixir module

Version 38

2017-01-01, 22:02:06

Version 39

2017-01-03, 11:11:50

Idiom #45 Pause execution for 5 seconds

Sleep for 5 seconds in current thread, before proceeding with next instructions.

Illustration

Idiom #45 Pause execution for 5 seconds

Sleep for 5 seconds in current thread, before proceeding with next instructions.

Illustration
Code
:timer.sleep(5000)
Code
Process.sleep(5000)
Comments bubble
Elixir can leverage Erlang's stdlib, one of them is the :timer module, which has a sleep(milliseconds) function.
Comments bubble
Sleeps the current process by timeout.

timeout is either the number of milliseconds to sleep as an integer or the atom :infinity. When :infinity is given, the current process will suspend forever.
Doc URL
https://hexdocs.pm/elixir/Process.html#sleep/1
Demo URL
http://elixirplayground.com?gist=b7e05b38a5263b46ff72