Skip to content

Instantly share code, notes, and snippets.

@joaodrp
Created January 12, 2012 19:04
Show Gist options
  • Save joaodrp/1602417 to your computer and use it in GitHub Desktop.
Save joaodrp/1602417 to your computer and use it in GitHub Desktop.
# server.rb
require 'goliath'
module MyApp
class Server < Goliath::API; end
end
# ----------------
# api.rb
require 'em-synchrony'
require 'em-synchrony/em-http'
class API
attr_reader :host, :port
def initialize(opts = {})
@host = opts[:host]
@port = opts[:port]
end
def get_index
http = EventMachine::HttpRequest.new("http://#{@host}:#{@port}/").get
http.response
end
end
# ----------------
# project_loader.rb
require "server.rb"
require "api.rb"
require ...
# ----------------
# testing file
require "project_loader"
client = API.new(host: 'google.com', port: 80)
EM.synchrony do
p client.get_index
EM.stop
end
# result => "<HTML><HEAD>..." but do not exit!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment