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

Thinking in Actors

Thinking in Actors

Using Erlang style actors to implement a highly concurrent system. Presented on WebCampZg (http://2014.webcampzg.org/).

Saša Jurić

October 04, 2014
Tweet

More Decks by Saša Jurić

Other Decks in Programming

Transcript

  1. defmodule BankAccount do use ExActor.GenServer definit do initial_state(0) end defcast

    deposit(amount), state: balance do new_state(balance + amount) end defcast deposit(amount), state: balance do if amount <= balance do new_state(balance – amount) else new_state(balance) end end defcall balance, state: balance do reply(balance) end end
  2. account = find_account(id) BankAccount.withdraw(account,200) account = find_account(id) BankAccount.deposit(account,300) account =

    find_account(id) balance = BankAccount.balance(account) client 1 client 2 client 3 account = BankAccount.start
  3. tcp listener xml assembler model builder serializer persister dispatcher message

    6 message 5 message 4 message 3 message 2 message 1
  4. <message> <match id=”1” ...> ... </match> <match id=”2” ...> ...

    </match> ... <match id=”n” ...> ... </match> </message>
  5. i