In Elixir how can you spawn a long running process (tail-called) that sleeps without hanging IEX?
def longrunner() do
IO.puts "do something..."
:timer.sleep(10000) // :timer.sleep blocks IEX repl
myrunner = spawn(longrunner)
the problem is how you are calling it.
spawn(longrunner) tries to run and evaluate the
longrunner function (due to optional parentheses) before it calls
spawn . That is why it is hanging.
myrunner = spawn(fn() -> longrunner() end)
longrunner is not a variable/binding, it is a function, thus it is actually doing this:
myrunner = spawn(longrunner())
Of which would never return so spawn never even gets called. You probably want to pass the function rather than call the function:
myrunner = spawn(&longrunner/0)