Skip to content

Instantly share code, notes, and snippets.

@jki127
Last active December 12, 2018 19:17
Show Gist options
  • Save jki127/83e79a3971639eada3698715680df675 to your computer and use it in GitHub Desktop.
Save jki127/83e79a3971639eada3698715680df675 to your computer and use it in GitHub Desktop.

Elixir - DistSys Lecture - Dec 11th, 2018

Actor Model

  • ID

  • stack

  • msg queue (incoming)

  • Two actors have no shared memory

One of the actors has a counter. I want other actors to be able to increment the counter and be able to get the value of the counter

We’ll make two messages: { QUERY : my_pid; } { INCREMENT }

Elixir

send self(), {:TEST} # send message

# how to receieve messages
# receive blocks until it receives the message
receive do
	{:TEST} -> IO.puts("Got it!")
	# after receiving, the message is deleted from the message
	# queue
end

Node 1

# Name the current process so others can communicate with it
Process.register self(), :bestprocess

receive do {:TEST, x} -> IO.puts(x) end

Node 2

# send a message to the "bestprocess" process on the node
# "foo@tenger"
send {:bestprocess, :"foo@tenger"}, {:TEST, "barf"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment