Permalink
Browse files

Stop propagating events after stop.

  • Loading branch information...
1 parent 2f0c6ec commit 2abcea8008b14182959834e54a76978eb17935e4 @ConradIrwin committed Jul 2, 2011
Showing with 27 additions and 0 deletions.
  1. +1 −0 lib/em-imap/listener.rb
  2. +26 −0 spec/listener_spec.rb
View
1 lib/em-imap/listener.rb
@@ -92,6 +92,7 @@ module ListeningDeferrable
# Register a block to be called when receive_event is called.
def listen(&block)
listeners << block
+ stopback{ |*args| listeners.delete block }
self
end
View
26 spec/listener_spec.rb
@@ -54,6 +54,32 @@
a.should == [2]
end
+ it "should not propagate events after stopped" do
+ a = []
+
+ listener = EM::IMAP::Listener.new.listen do |event|
+ a << event
+ end
+
+ listener.receive_event 1
+ listener.stop
+ listener.receive_event 2
+ a.should == [1]
+ end
+
+ it "should continue propagating events started before stopped" do
+ a = []
+ listener = EM::IMAP::Listener.new.listen do |event|
+ listener.stop
+ end.listen do |event|
+ a << event
+ end
+
+ listener.receive_event 1
+ listener.receive_event 2
+ a.should == [1]
+ end
+
describe "transform" do
before :each do
@bottom = EM::IMAP::Listener.new

0 comments on commit 2abcea8

Please sign in to comment.