Sha256: 2f61542c97692cf02129810d00888a7c1dc8a06acd470ea2fdd0ba3701400dd2
Contents?: true
Size: 777 Bytes
Versions: 3
Compression:
Stored size: 777 Bytes
Contents
require 'sucker' require 'em-synchrony' require 'em-synchrony/em-http' module Sucker # We minimally patch Request and Response to make them fiber-aware. class Request def adapter @adapter ||= EM::HttpRequest end # Performs an evented request and yields a response to given block. def aget(&block) http = EM::HttpRequest.new(url).aget http.callback { block.call(Response.new(http)) } http.errback { block.call(Response.new(http)) } end # Performs an evented request and returns a response. def get http = EM::HttpRequest.new(url).get Response.new(http) end end class Response def initialize(http) self.body = http.response self.code = http.response_header.status end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sucker-2.1.0 | lib/sucker/synchrony.rb |
sucker-2.0.0 | lib/sucker/synchrony.rb |
sucker-2.0.0.pre.5 | lib/sucker/synchrony.rb |