Permalink
Browse files

Use DefaultDeferrable to deal with exceptions

  • Loading branch information...
1 parent c2e3243 commit cf2a2d26c549dfbeef0913b05fa07b85642f7abe @meh committed Apr 15, 2012
Showing with 8 additions and 2 deletions.
  1. +2 −0 lib/em-socksify/socks5.rb
  2. +6 −2 lib/em-socksify/socksify.rb
@@ -100,6 +100,8 @@ def socks_parse_response
socks_unhook(ip)
end
+ rescue Exception => e
+ @socks_deferable.fail(e)
end
def socks_methods
@@ -7,11 +7,15 @@ def socksify(host, port, username = nil, password = nil, version = 5, &blk)
@socks_username = username
@socks_password = password
@socks_version = version
- @socks_callback = blk
@socks_data = ''
socks_hook
socks_send_handshake
+
+ @socks_deferable = DefaultDeferrable.new
+ @socks_deferable.callback(&blk) if blk
+ @socks_deferable.errback { |e| raise e }
+ @socks_deferable
end
def socks_hook
@@ -31,7 +35,7 @@ class << self
remove_method :receive_data
end
- @socks_callback.call(ip)
+ @socks_deferable.succeed(ip)
end
def socks_receive_data(data)

0 comments on commit cf2a2d2

Please sign in to comment.