Created
September 24, 2010 20:29
-
-
Save adimircolen/595982 to your computer and use it in GitHub Desktop.
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
# Ruby 1.9 | |
require 'rubygems' | |
require 'eventmachine' | |
##require 'lib/environment' # here we go again! | |
##require 'sequel' | |
EM.kqueue = true if EM.kqueue? # file watching requires kqueue on OSX | |
module Example < EM::Connection | |
def receive_data(data) | |
p = proc{ | |
d = 0 | |
p "Received #{data}" | |
# loop just to keep the processor busy | |
# this work of processor will be sqls selects ena inserts | |
(0...999999).each{|i| d += (i%2.0)**i} | |
p "On operations #{d} with #{data}" | |
d | |
} | |
c = proc{|r| | |
p "Using return of op #{r} with #{data}" | |
send_data(r) | |
} | |
EM.defer(p, c) | |
p "The end of receive_data #{data}" | |
end | |
end | |
EM.run do | |
EM.start_server(HOST, HOST_PORT, Example) | |
end | |
puts("Shutdown this service") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment