Skip to content

Instantly share code, notes, and snippets.

@adimircolen
Created September 24, 2010 20:29
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 adimircolen/595982 to your computer and use it in GitHub Desktop.
Save adimircolen/595982 to your computer and use it in GitHub Desktop.
# 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