Browse files

multi.rb: Fixed bugs last two commits introduced. See:

  I am terribly sorry, it seems that last two commits didn't work
  correctly. I should have tested it before committing...

  1. In the first commit, connections passed via .new didn't respect
     previous semantics. They didn't setup callback correctly,
     thus the callback block might never be called...

     To solve this, use add(*conns) instead of directly setup @requests.

  2. In the second commit, MultiRequest itself didn't pass to the
     callback... To solve this, simply pass self to succeed.
     It's ok that Ruby block would ignore the argument if the block
     didn't say it wanted. e.g.

       def f, &block


       f{} # ok
  • Loading branch information...
1 parent d701e38 commit e6856c86c0d13c846205390fca70219a48285c0f @godfat committed Jul 31, 2010
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/em-http/multi.rb
@@ -29,8 +29,9 @@ class MultiRequest
attr_reader :requests, :responses
def initialize(conns=[], &block)
- @requests = conns
+ @requests = []
@responses = {:succeeded => [], :failed => []}
+ add(*conns)
callback(&block) if block_given?
@@ -45,7 +46,8 @@ def add(conn)
# invoke callback if all requests have completed
def check_progress
- succeed if (@responses[:succeeded].size + @responses[:failed].size) == @requests.size
+ succeed(self) if (@responses[:succeeded].size +
+ @responses[:failed] .size) == @requests.size

0 comments on commit e6856c8

Please sign in to comment.