Sha256: 223e400e9d4260cc0ed19c3cf61d93a1f0220290fc77f606c8ca2ac0cbcf4f3a

Contents?: true

Size: 780 Bytes

Versions: 1

Compression:

Stored size: 780 Bytes

Contents

module Sideband
  class Manager

    def initialize
      @pid = ::Process.pid
      thread!
      queue!
    end

    def queue
      handle_fork
      handle_dead_thread
      @queue
    end

    def thread
      @thread
    end

    def join
      @queue.kill
      @thread.join
    end

    def kill
      @thread.kill
      @thread = @queue = nil
    end

    private

    def queue!
      @queue = Sideband::Queue.new
    end

    def thread!
      @thread.kill if @thread
      @thread = Sideband::Thread.new(self)
    end

    def handle_fork
      if ::Process.pid != @pid
        @pid = ::Process.pid
        thread!
        queue!
      end
    end

    def handle_dead_thread
      unless (@thread && @thread.thread.alive?)
        thread!
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sideband-1.0.4 lib/sideband/manager.rb