Permalink
Browse files

Added send_async2 and trigger_async2 methods without Deferrable for u…

…sage in Goliath
  • Loading branch information...
1 parent 526e3c6 commit 7f4f975a9185884d36a44508005fc8382e07c7d1 @rfelix committed Oct 31, 2011
Showing with 24 additions and 0 deletions.
  1. +5 −0 lib/pusher/channel.rb
  2. +19 −0 lib/pusher/request.rb
View
@@ -29,6 +29,11 @@ def trigger_async(event_name, data, socket_id = nil, &block)
request.send_async
end
+ def trigger_async2(event_name, data, socket_id = nil, &block)
+ request = construct_event_request(event_name, data, socket_id)
+ request.send_async2
+ end
+
# Trigger event
#
# @example
View
@@ -81,6 +81,25 @@ def send_async
deferrable
end
+ def send_async2
+ unless defined?(EventMachine) && EventMachine.reactor_running?
+ raise Error, "In order to use trigger_async you must be running inside an eventmachine loop"
+ end
+ require 'em-http' unless defined?(EventMachine::HttpRequest)
+
+ http = EventMachine::HttpRequest.new(@uri).post({
+ :query => @params, :timeout => 5, :body => @body,
+ :head => {'Content-Type'=> 'application/json'}
+ })
+ http.callback {
+ handle_response(http.response_header.status, http.response.chomp)
+ }
+ http.errback {
+ Pusher.logger.debug("Network error connecting to pusher: #{http.inspect}")
+ Error.new("Network error connecting to pusher")
+ }
+ end
+
private
def handle_response(status_code, body)

0 comments on commit 7f4f975

Please sign in to comment.