Skip to content

Instantly share code, notes, and snippets.

@l1x
Created February 1, 2011 21:52
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 l1x/806765 to your computer and use it in GitHub Desktop.
Save l1x/806765 to your computer and use it in GitHub Desktop.
tutrial
run() ->
Pid = spawn(fun ping/0),
Pid ! self(),
receive
pong -> ok
end.
ping() ->
receive
From -> From ! pong
end.
@l1x
Copy link
Author

l1x commented Feb 1, 2011

|23:18:11| (ismarc) ok, so, starting at the beginning, we have two functions defined, run() and ping()
|23:18:30| (ismarc) spawn takes a function that you want to be spawned in another process
|23:19:11| (ismarc) The Pid of the spawned process is stored
|23:19:43| (ismarc) it then sends the Pid to itself in the initial process
|23:19:48| (ismarc) you could send any message here
|23:20:03| (ismarc) The ping function receives a message (any message)
|23:20:33| (ismarc) err, I explained it backwards
|23:20:43| (ismarc) it sends its own Pid to the Pid it spawned
|23:21:06| (ismarc) the ping function receives the Pid of the initial process and sends the message pong to it
|23:21:30| (ismarc) the original process went into receive mode and if it receives a message back of pong, it results in ok

@l1x
Copy link
Author

l1x commented Feb 1, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment