Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elixir - valentine edition

Saša Jurić
February 14, 2017

Elixir - valentine edition

Saša Jurić

February 14, 2017
Tweet

More Decks by Saša Jurić

Other Decks in Programming

Transcript

  1. Elixir @sasajuric aircloak.com

  2. None
  3. None
  4. otpornost na pogreške skalabilnost responzivnost

  5. Erlang LFE Elixir Erlang VM (BEAM)

  6. None
  7. v1 = f1(p1, p2, ...) v2 = f2(...) ...

  8. spawn(fn -> ... end) A B

  9. OS proces BEAM proces

  10. scheduler scheduler scheduler scheduler BEAM instanca CPU CPU CPU CPU

  11. pid = spawn(fn -> ... end)

  12. pid = spawn(fn -> ... end) send(pid, :ping)

  13. spawn(fn -> receive do :ping -> # ... end end)

  14. send(pid, {:ping, self()})

  15. spawn(fn -> receive do {:ping, caller_pid} -> send(caller_pid, :pong) end

    end)
  16. send(pid, {:ping, self()}) receive do :pong -> # ... after

    :timer.seconds(5) -> # ... end
  17. pid = spawn(fn -> server_loop(state) end)

  18. defp server_loop(state) do receive do message -> new_state = handle(state,

    message) server_loop(new_state) end end
  19. bank account balance

  20. send(pid, {:deposit, 100}) send(pid, {:withdraw, 100}) send(pid, {:balance, self()}) receive

    do balance -> # ... end
  21. spawn(fn -> bank_account_loop(0) end)

  22. def bank_account_loop(balance) do receive do {:deposit, amount} -> bank_account_loop(balance +

    amount) {:withdraw, amount} -> bank_account_loop(balance - amount) {:balance, caller_pid} -> send(caller_pid, balance) bank_account_loop(balance) end end
  23. bank account {:deposit, amount} {:withdraw, amount} :balance

  24. None
  25. db connection background job request handler state request handler request

    handler request handler request handler request handler state state state background job background job background job db connection db connection db connection
  26. A B C D E F

  27. A exit notifikacija B C D E F

  28. S S S W W S W W W S

    W W
  29. VM VM VM VM VM

  30. VM send(pid, message) VM 1 send(pid, message) VM 2

  31. elixir-lang.org phoenixframework.org adventofcode.com exercism.io elixirforum.com meetup.com/lambdazagreb/