Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow fail_all to end the connection and fail everything.

  • Loading branch information...
commit 3a97981a4918cd02737a966fbb788a1005639ce5 1 parent f9ed928
@ConradIrwin ConradIrwin authored
Showing with 16 additions and 4 deletions.
  1. +6 −4 lib/em-imap/connection.rb
  2. +10 −0 spec/client_spec.rb
View
10 lib/em-imap/connection.rb
@@ -97,12 +97,14 @@ def listen_for_greeting
end
# Called when the connection is closed.
- # If there are any listeners left, we fail them.
- # (TODO: Should we actually succeed them if the connection was
- # explicitly closed by us?)
# TODO: Figure out how to send a useful error...
def unbind
- @listeners.each{ |listener| listener.fail EOFError.new("Connection to IMAP server was unbound") }
+ fail_all EOFError.new("Connection to IMAP server was unbound"), true
+ end
+
+ def fail_all(error, closed=false)
+ @listeners.each{ |listener| listener.fail error }
+ close_connection unless closed
end
def add_to_listener_pool(listener)
View
10 spec/client_spec.rb
@@ -96,6 +96,16 @@
@connection.receive_data "* RUBY0001 OK Success\r\n"
end
+ it "should fail all concurrent commands if something goes wrong" do
+ a = b = false
+ @client.create("Encyclop\xc3\xa6dia").errback{ |e| a = true }
+ @client.create("Brittanica").errback{ |e| b = true }
+ @connection.should_receive(:close_connection).once
+ @connection.fail_all EOFError.new("Testing error")
+ a.should == true
+ b.should == true
+ end
+
describe "login" do
it "should callback on a successful login" do
a = nil
Please sign in to comment.
Something went wrong with that request. Please try again.