Skip to content

Instantly share code, notes, and snippets.

@careo
Created September 30, 2009 00:38
Show Gist options
  • Select an option

  • Save careo/197574 to your computer and use it in GitHub Desktop.

Select an option

Save careo/197574 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'eventmachine'
require 'fcntl'
#$stderr.sync = true
#$stdout.sync = true
#
$r,$w=IO::pipe
$stderr.reopen $w
$stderr.write("bah\n")
puts $r.readline
module Handler
def notify_readable
puts $r.read
end
#def receive_data data
# data
#end
end
def set_nonblocking(io)
val = io.fcntl(Fcntl::F_GETFL)
return io.fcntl(Fcntl::F_SETFL, val | Fcntl::O_NONBLOCK)
end
set_nonblocking($r)
EM.run do
EM.attach $r, Handler
EM::PeriodicTimer.new(0.5) { $stderr.write("blah\n") }
EM.add_timer(5) { EM.stop }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment