lib/onstomp/components/threaded_processor.rb in onstomp-1.0.0pre1 vs lib/onstomp/components/threaded_processor.rb in onstomp-1.0.0

- old
+ new

@@ -5,10 +5,11 @@ # Creates a new processor for the {OnStomp::Client client} # @param [OnStomp::Client] client def initialize client @client = client @run_thread = nil + @closing = false end # Returns true if its IO thread has been created and is alive, otherwise # false. # @return [true,false] @@ -23,16 +24,28 @@ def start @run_thread = Thread.new do begin while @client.connected? @client.connection.io_process + Thread.stop if @closing end rescue OnStomp::StopReceiver rescue Exception raise end end self + end + + # Prepares the conneciton for closing by flushing its write buffer. + def prepare_to_close + if running? + @closing = true + Thread.pass until @run_thread.stop? + @client.connection.flush_write_buffer + @closing = false + @run_thread.wakeup + end end # Causes the thread this method was invoked in to +pass+ until the # processor is no longer {#running? running}. # @return [self]