defmodule Foo do async def bar(x) # code end end
task = Task.async(fn -> Foo.bar(:arg) end) Task.await(task)
task = Task.async(Foo, :bar, [:arg]) Task.await(task)
Beautiful is
better than ugly,
Explicit is better than implicit,
Simple is better than complex,
Complex is better than complicated.
The Zen of Python, by Tim Peters
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAJbPmJM_TAtuV5b39ZaC1gd8njtHCyk3xe2_%2BfdgfwhOcA-L7Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
defmodule DefAsync do
defmacro defasync(call, do: block) do
quote do
def unquote(call) do
Task.async(fn -> unquote(block) end)
end
end
end
end
defmodule Foo do
import DefAsync
defasync delayed_foo(value) do
:timer.sleep(1_000)
IO.inspect value
end
end
Foo.delayed_foo(42) |> Task.await()
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/749338f8-ab6b-4849-a440-052a96686e95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.