lib/chillout/client.rb in chillout-0.5.4 vs lib/chillout/client.rb in chillout-0.6.0

- old
+ new

@@ -33,33 +33,34 @@ @queue = Queue.new @worker_mutex = Mutex.new end def enqueue(creations) - ensure_worker_running + start_worker @logger.info "Creations were enqueued." @queue << creations end def worker_running? @worker_thread && @worker_thread.alive? end - private def start_worker - @worker_thread = Thread.new do - worker = Worker.new(@dispatcher, @queue, @logger) - worker.run - end - end - - def ensure_worker_running return if worker_running? @worker_mutex.synchronize do return if worker_running? - start_worker + @worker_thread = Thread.new do + begin + worker = Worker.new(@dispatcher, @queue, @logger) + worker.run + ensure + @logger.flush + end + end end end + + private def build_config(config_or_api_key, options) case config_or_api_key when Config @config = config_or_api_key