Created
August 16, 2013 15:28
-
-
Save headius/6250897 to your computer and use it in GitHub Desktop.
"goroutines" and "channels" implemented for Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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