From: "Ara.T.Howard" Date: 2005-06-29T05:54:40+09:00 Subject: Re: C-like ugliness of Kernel#select On Wed, 29 Jun 2005, C Erler wrote: > IO has such methods as #closed? and #eof? to find much-needed information > about IO status, but it doesn't have anything like #read_ready? or > #write_ready? that would be useful for anyone not wanting blocking IO. The > only way to do this is with the C-like ugly-hackishness that is > Kernel#select. > > Does anyone have a good argument for not adding a few more methods to IO in > the Ruby distribution itself ? Does anybody think it would be a good idea to > submit this as an RCR ? If those are added, would we be able to remove > Kernel#select in the next "we don't care about backward compatibility" Ruby > version ? harp:~ > cat a.rb require 'io/wait' STDOUT.sync = true pipe = IO::popen 'while true;do sleep 2; echo 42; done' threads = [] threads << Thread::new{ loop{ puts "not blocked @ <#{ Time::now }>"; sleep 0.42 } } threads << Thread::new{ loop{ (pipe.ready? and puts("buf <#{ pipe.gets.chomp }>")) or sleep 0.42 } } threads.each{|t| t.join} harp:~ > ruby a.rb not blocked @ not blocked @ not blocked @ not blocked @ not blocked @ buf <42> not blocked @ not blocked @ not blocked @ not blocked @ not blocked @ buf <42> not blocked @ not blocked @ not blocked @ not blocked @ not blocked @ buf <42> not blocked @ not blocked @ not blocked @ not blocked @ buf <42> not blocked @ ... ... ... know yer standard libs ;-) i don't think this work on windows - but it is in the standard dist. hth. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================