Created
May 23, 2014 19:28
-
-
Save headius/18b13017e1a6cdd1d297 to your computer and use it in GitHub Desktop.
Selectable process IO on JRuby...normally impossible on JVM
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/jruby $ cat process_select.rb | |
io = open("|cat", "r+") | |
Thread.new { | |
loop { | |
sleep 1 | |
io.write("hello") | |
} | |
} | |
Thread.new { | |
loop { | |
1 until IO.select([io]) | |
ret = io.read_nonblock(5, :exception => false) | |
puts ret unless ret == :wait_readable | |
} | |
} | |
sleep | |
system ~/projects/jruby $ jruby -v process_select.rb | |
jruby 9000.dev-SNAPSHOT (2.1.2) 2014-05-22 1a2daf7 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_45-b18 [darwin-x86_64] | |
hello | |
hello | |
hello | |
hello | |
hello | |
hello | |
hello | |
hello | |
hello | |
hello | |
hello | |
^C | |
system ~/projects/jruby $ rvm jruby do ruby -v process_select.rb | |
jruby 1.7.12 (1.9.3p392) 2014-04-15 643e292 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_45-b18 [darwin-x86_64] | |
HANGS!^C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment