File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ module Watcher
1010 def initialize ( client , deferable )
1111 @client = client
1212 @deferable = deferable
13+ @is_watching = true
1314 end
1415
1516 def notify_readable
@@ -22,11 +23,19 @@ def notify_readable
2223 @deferable . succeed ( result )
2324 end
2425 end
26+
27+ def watching?
28+ @is_watching
29+ end
30+
31+ def unbind
32+ @is_watching = false
33+ end
2534 end
2635
2736 def close ( *args )
2837 if @watch
29- @watch . detach
38+ @watch . detach if @watch . watching?
3039 end
3140 super ( *args )
3241 end
Original file line number Diff line number Diff line change 108108 callbacks_run . should == [ :errback ]
109109 end
110110 end
111+
112+ it "should not raise error when closing client with no query running" do
113+ callbacks_run = [ ]
114+ EM . run do
115+ client = Mysql2 ::EM ::Client . new DatabaseCredentials [ 'root' ]
116+ defer = client . query ( "select sleep(0.025)" )
117+ defer . callback do |result |
118+ callbacks_run << :callback
119+ end
120+ defer . errback do |err |
121+ callbacks_run << :errback
122+ end
123+ EM . add_timer ( 0.1 ) do
124+ lambda {
125+ client . close
126+ } . should_not raise_error ( /invalid binding to detach/ )
127+ EM . stop_event_loop
128+ end
129+ end
130+ callbacks_run . should == [ :callback ]
131+ end
111132 end
112133rescue LoadError
113134 puts "EventMachine not installed, skipping the specs that use it"
You can’t perform that action at this time.
0 commit comments