Sha256: 8137b1e5fb11e104ffe1f03e387810be34beae5a4ccda8d488502dd4d0d035b9

Contents?: true

Size: 556 Bytes

Versions: 8

Compression:

Stored size: 556 Bytes

Contents

module WatCatcher
  class Backgrounder
    def initialize
      @queue = Queue.new
      background_thread

      at_exit do
        @queue << false
        background_thread.join()
      end
    end


    def queue &block
      p "queueing"
      @queue << block
    end

    def background_thread
      @thread ||= Thread.new do
        running = true
        while running || !@queue.empty?
          msg = @queue.pop
          if msg
            msg.call
          else
            running = false
          end
        end
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wat_catcher-0.0.8 lib/wat_catcher/backgrounder.rb
wat_catcher-0.0.7 lib/wat_catcher/backgrounder.rb
wat_catcher-0.0.6 lib/wat_catcher/backgrounder.rb
wat_catcher-0.0.5 lib/wat_catcher/backgrounder.rb
wat_catcher-0.0.4 lib/wat_catcher/backgrounder.rb
wat_catcher-0.0.3 lib/wat_catcher/backgrounder.rb
wat_catcher-0.0.2 lib/wat_catcher/backgrounder.rb
wat_catcher-0.0.1 lib/wat_catcher/backgrounder.rb