lib/onstomp/components/threaded_processor.rb in onstomp-1.0.4 vs lib/onstomp/components/threaded_processor.rb in onstomp-1.0.5

- old
+ new

@@ -28,11 +28,13 @@ @client.connection.io_process Thread.stop if @closing end rescue OnStomp::StopReceiver rescue Exception - raise + # FIXME: This is pretty hacky, too. The problem is one of race + # conditions and how we access the connection. + raise if @run_thread == Thread.current end end self end @@ -61,15 +63,18 @@ # @return [self] # @raise [IOError, SystemCallError] if either were raised in the IO thread # and the {OnStomp::Client client} is still # {OnStomp::Client#connected? connected} after the thread is joined. def stop - begin - @run_thread.raise OnStomp::StopReceiver if @run_thread.alive? - @run_thread.join - rescue IOError, SystemCallError - raise if @client.connected? + if @run_thread + begin + @run_thread.raise OnStomp::StopReceiver if @run_thread.alive? + @run_thread.join + rescue OnStomp::StopReceiver + rescue IOError, SystemCallError + raise if @client.connected? + end + @run_thread = nil end - @run_thread = nil self end end