Skip to content

Instantly share code, notes, and snippets.

@careo
Created March 6, 2009 04:50
Show Gist options
  • Select an option

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

Select an option

Save careo/74763 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'eventmachine'
module EventMachine
module ChildProcess
def initialize
@buffer = []
end
def receive_data data
puts "------"
puts data
puts "------"
end
def unbind
p get_status
p get_status.exitstatus
end
end
def EM.spawn cmd, &cb
EM.popen cmd, ChildProcess do |c|
p c
end
end
end
EM.run{
EM.add_periodic_timer(1) {
print "."
}
EM.spawn('ruby long-running-child.rb') do |results|
puts results
end
EM.add_timer(15) {
EM.stop
}
}
require 'rubygems'
require 'eventmachine'
EM.run {
EM.add_periodic_timer(1) {
puts "tick"
}
EM.add_timer(10) {
puts "done"
EM.stop
}
}
#<#<Class:0x500898>:0x500618 @signature="8e0ebeef062bf970d9f5271429d793233", @buffer=[]>
.........------
tick
tick
tick
tick
tick
tick
tick
tick
tick
done
------
#<Process::Status: pid=12937,exited(0)>
0
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment