Skip to content

Instantly share code, notes, and snippets.

@vito
Created July 29, 2010 16:09
Show Gist options
  • Save vito/498532 to your computer and use it in GitHub Desktop.
Save vito/498532 to your computer and use it in GitHub Desktop.
-- starts a match of n volleys
volley: (n: Integer) = {
-- start up the ponger
proc = { notify |
pong: notify
} spawn-with: [self]
-- start up the pinger
{ ping: n ponger: proc } spawn
} do
pong: notify =
receive match: {
-- volley is done finish
@finished -> {
" | ." write
"volley finished" write
notify ! @done
} do
-- got a ping, send a pong
@(ping: pid) -> {
" . |" write
pid ! @pong
pong: notify -- loop
} do
}
ping: 0 ponger: pid = pid ! @finished
ping: n ponger: pid = {
pid ! @(ping: self)
-- got a pong send a ping
receive match: {
@pong -> {
"| . " write
ping: (n - 1) ponger: pid
} do
}
} do
-- start up the match, doing 5 volleys
volley: 5
-- wait for the match to complete
receive print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment