Skip to content

Instantly share code, notes, and snippets.

@headius
Created May 23, 2014 19:28
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 headius/18b13017e1a6cdd1d297 to your computer and use it in GitHub Desktop.
Save headius/18b13017e1a6cdd1d297 to your computer and use it in GitHub Desktop.
Selectable process IO on JRuby...normally impossible on JVM
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