Class: Worker::Threader
- Inherits:
-
Object
- Object
- Worker::Threader
- Defined in:
- lib/buzzcore/thread_utils.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(aWorkerClass, &aCreateBlock) ⇒ Threader
constructor
A new instance of Threader.
- #start(aTimeout = 0.1) ⇒ Object
- #stop(aTimeout = 0.1) ⇒ Object
Constructor Details
#initialize(aWorkerClass, &aCreateBlock) ⇒ Threader
Returns a new instance of Threader.
491 492 493 494 495 496 497 498 499 |
# File 'lib/buzzcore/thread_utils.rb', line 491 def initialize(aWorkerClass,&aCreateBlock) @create_proc = aCreateBlock @worker_class = aWorkerClass if @create_proc @worker = @create_proc.call(@worker_class) else @worker = @worker_class.new end end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
483 484 485 |
# File 'lib/buzzcore/thread_utils.rb', line 483 def thread @thread end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
483 484 485 |
# File 'lib/buzzcore/thread_utils.rb', line 483 def worker @worker end |
Class Method Details
Instance Method Details
#start(aTimeout = 0.1) ⇒ Object
501 502 503 504 |
# File 'lib/buzzcore/thread_utils.rb', line 501 def start(aTimeout=0.1) @thread = Thread.new(@worker) { |aWorker| aWorker.main_proc } @worker.wait_for_started(aTimeout) end |
#stop(aTimeout = 0.1) ⇒ Object
506 507 508 509 510 511 512 513 |
# File 'lib/buzzcore/thread_utils.rb', line 506 def stop(aTimeout=0.1) @worker.stop @worker.wait_for_stopped(aTimeout) @thread.exit unless !@thread or (@thread.join(0) and not @thread.alive?) #@thread.join() @worker = nil @thread = nil end |