Sha256: b0829bd7e0e59c4069c7afdc3ddce57b487ac80cd8c2d6e81acbc8f2e9d665ac

Contents?: true

Size: 538 Bytes

Versions: 2

Compression:

Stored size: 538 Bytes

Contents

module Sideband
  class Thread

    attr_reader :thread

    def initialize(manager)
      @manager = manager
      @thread = ::Thread.new do
        while @manager.queue && work = @manager.queue.pop
          exit if work.nil?
          
          begin
            work.call
          rescue Exception
            # Sideband will ignore all Exceptions, 
            # better to handle in your workers.
          end
        end
      end
    end

    def join
      thread.join
    end

    def kill
      thread.kill
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sideband-1.0.3 lib/sideband/thread.rb
sideband-1.0.2 lib/sideband/thread.rb