Skip to content

Instantly share code, notes, and snippets.

@tuvokki
Created March 26, 2018 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuvokki/5a29dd8d690808ce9bfb754fbdf50b83 to your computer and use it in GitHub Desktop.
Save tuvokki/5a29dd8d690808ce9bfb754fbdf50b83 to your computer and use it in GitHub Desktop.
iex(1)> lala = fn(msg) -> send self(), {:hello, msg} end
#Function<6.99386804/1 in :erl_eval.expr/5>
iex(2)> lala.("hehe")
{:hello, "hehe"}
iex(3)> lala.("hoho")
{:hello, "hoho"}
iex(4)> getst = fn() -> receive do {:hello, msg} -> "Got this #{inspect msg}" after 1_000 -> "Nothing after 1s" end end
#Function<20.99386804/0 in :erl_eval.expr/5>
iex(5)> getst.()
"Got this \"hehe\""
iex(6)> getst.()
"Got this \"hoho\""
iex(7)> getst.()
"Nothing after 1s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment