Skip to content

Instantly share code, notes, and snippets.

@headius
Created August 16, 2013 15:28
Show Gist options
  • Save headius/6250897 to your computer and use it in GitHub Desktop.
Save headius/6250897 to your computer and use it in GitHub Desktop.
"goroutines" and "channels" implemented for Ruby
system ~/projects/joe $ cat pingpong.rb
require 'target/joe-1.0-SNAPSHOT.jar'
com.headius.joe.JoeLibrary.new.load(JRuby.runtime, false)
# pinger ponger printer
def pinger(c)
20.times do
c << 'ping'
end
end
def ponger(c)
20.times do
c << 'pong'
end
end
def printer(c)
40.times do
puts c.take
sleep 1
end
end
c = chan
joe {pinger(c)}
joe {ponger(c)}
joe {printer(c)}
system ~/projects/joe $ jruby pingpong.rb
ping
pong
ping
pong
ping
pong
ping
pong
ping
pong
ping
pong
ping
pong
^C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment