Permalink
Browse files

raise error on duplicate key in Multi, closes #86

  • Loading branch information...
1 parent f07b2a1 commit 9521261b5ceff592e31328ea560d8ba42ca6953a @igrigorik igrigorik committed Nov 26, 2011
Showing with 18 additions and 2 deletions.
  1. +4 −2 lib/em-synchrony/em-multi.rb
  2. +13 −0 spec/multi_spec.rb
  3. +1 −0 spec/synchrony_spec.rb
@@ -6,16 +6,18 @@ class Multi
attr_reader :requests, :responses
def initialize
- @requests = []
+ @requests = {}
@responses = {:callback => {}, :errback => {}}
end
def add(name, conn)
+ raise 'Duplicate Multi key' if @requests.key? name
+
fiber = Fiber.current
conn.callback { @responses[:callback][name] = conn; check_progress(fiber) }
conn.errback { @responses[:errback][name] = conn; check_progress(fiber) }
- @requests.push(conn)
+ @requests[name] = conn
end
def finished?
View
@@ -0,0 +1,13 @@
+require "helper/all"
+
+describe EM::Synchrony do
+ describe "Multi" do
+ it "should require unique keys for each deferrable" do
+ lambda do
+ m = EM::Synchrony::Multi.new
+ m.add :df1, EM::DefaultDeferrable.new
+ m.add :df1, EM::DefaultDeferrable.new
+ end.should raise_error("Duplicate Multi key")
+ end
+ end
+end
@@ -26,4 +26,5 @@
}.resume
end
end
+
end

0 comments on commit 9521261

Please sign in to comment.