Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix same race-condition in listeners.

  • Loading branch information...
commit 2f0c6ec9aab922ff7b1f721e3d4255033c13fba6 1 parent 4f0bf50
@ConradIrwin ConradIrwin authored
Showing with 16 additions and 1 deletion.
  1. +3 −1 lib/em-imap/listener.rb
  2. +13 −0 spec/listener_spec.rb
View
4 lib/em-imap/listener.rb
@@ -97,7 +97,9 @@ def listen(&block)
# Pass arguments onto any blocks registered with listen.
def receive_event(*args, &block)
- listeners.each{ |l| l.call *args, &block }
+ # NOTE: Take a clone of listeners, so any listeners added by listen
+ # blocks won't receive these events.
+ listeners.clone.each{ |l| l.call *args, &block }
end
# Register a block to be called when the ListeningDeferrable is stopped.
View
13 spec/listener_spec.rb
@@ -41,6 +41,19 @@
a.should == ["callback"]
end
+ it "should not pass events to listeners added in listen blocks" do
+ a = []
+ listener = EM::IMAP::Listener.new.listen do |event|
+ listener.listen do |event|
+ a << event
+ end
+ end
+
+ listener.receive_event 1
+ listener.receive_event 2
+ a.should == [2]
+ end
+
describe "transform" do
before :each do
@bottom = EM::IMAP::Listener.new
Please sign in to comment.
Something went wrong with that request. Please try again.