Skip to content

Instantly share code, notes, and snippets.

@ericsaboia
Created September 21, 2011 12:27
Show Gist options
  • Save ericsaboia/1231905 to your computer and use it in GitHub Desktop.
Save ericsaboia/1231905 to your computer and use it in GitHub Desktop.
Eventmachine Client
module EchoClient
ADDRESS = 'localhost'
PORT = 8081
class << self
def get(data)
result = ""
EventMachine::run do
EventMachine::connect(ADDRESS, PORT, EM).execute(data) do |stream|
result << stream
end
end
result
end
end
private
module EM
def receive_data(data)
@callback.call(data)
EventMachine::stop_event_loop # ends loop & resumes program flow
end
def execute(method, &callback)
@callback = callback
send_data(method)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment