You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simple example of the Elixir Concurrency Model and how to handle blocking processes.
Paste the below code into a file called concurrency_demo.ex and run $ elixir concurrency_demo.ex to run the example locally
defmoduleLogdodefplog(arg),do: IO.putsargdeffirst,do: log"first"defsecond,do: log"second"defslowfirstdo:timer.sleep(1000)first()endendIO.puts"RUN 1"Log.slowfirst()Log.second()# Outputs:# $ RUN 1# $ first# $ second# In "RUN 1" we see that `slowfirst` blocks `second` from runningIO.puts"RUN 2"task=Task.async(fn->Log.slowfirst()end)Log.second()# Outputs:# $ RUN 2# $ second# $ first# But in "RUN 2" we start `slowfirst` and then carry on with the scriptTask.await(task)# If you don't assign task and `await`, the program will finish and you won't see the log
The text was updated successfully, but these errors were encountered:
Simple example of the Elixir Concurrency Model and how to handle blocking processes.
Paste the below code into a file called
concurrency_demo.ex
and run$ elixir concurrency_demo.ex
to run the example locallyThe text was updated successfully, but these errors were encountered: