Sha256: a485a6bb2038c03c6656c1ed1e5b0ca35cb9f8ffbae1e5c4264b38de3494ce5b

Contents?: true

Size: 772 Bytes

Versions: 2

Compression:

Stored size: 772 Bytes

Contents

class Proco
module MT
# @private
module Threaded
  include Proco::Logger
  include Proco::MT::Base

  def initialize
    super
    @running = false
  end

  def running?
    @running
  end

  def exit
    broadcast do
      @running = false
    end
    @thread.join
  end

  def kill
    @running = false
    Thread.kill @thread if @thread
  end

  def spawn &block
    @thread = Thread.new do
      debug "#{Thread.current} started (#{self})"
      broadcast do
        @running = true
      end

      begin
        block.call
      rescue Exception => e
        error "[#{Thread.current}] #{e}"
        raise
      ensure
        debug "#{Thread.current} exited (#{self})"
      end
    end
    wait_until { running? }

    @thread
  end
end#Threaded
end#MT
end#Proco

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
proco-0.0.2 lib/proco/mt/threaded.rb
proco-0.0.1 lib/proco/mt/threaded.rb