Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix Client#close

  • Loading branch information...
commit dfcc8725aae6ead111d997e841cb33248553d23f 1 parent 95bbb25
@tmm1 authored
Showing with 13 additions and 1 deletion.
  1. +13 −1 rmongo.rb
View
14 rmongo.rb
@@ -11,6 +11,7 @@ module Client
def initialize opts = {}
@settings = opts
@id = 0
+ @responses = {}
@namespace = 'default.test'
timeout 2
errback{
@@ -51,6 +52,9 @@ def receive_data data
if cb = @responses.delete(response)
cb.call(results)
end
+
+ # close if no more responses pending
+ @on_close.succeed if @on_close and @responses.size == 0
end
end
@@ -108,6 +112,14 @@ def remove obj
# connection
+ def close
+ @on_close = EM::DefaultDeferrable.new
+ @on_close.callback{
+ close_connection
+ yield if block_given?
+ }
+ end
+
def self.connect opts = {}
opts[:host] ||= '127.0.0.1'
opts[:port] ||= 27017
@@ -206,7 +218,7 @@ def log *args
# log 'objects where n >= 1', :found, results
# end
- # mongo.close{ EM.stop_event_loop }
+ mongo.close{ EM.stop_event_loop }
}
__END__
Please sign in to comment.
Something went wrong with that request. Please try again.