Class: Bob::Engine::Threaded

Inherits:
Object
  • Object
show all
Defined in:
lib/bob/engine/threaded.rb

Overview

A thread pool based build engine. This engine simply adds jobs to an in-memory queue, and processes them as soon as possible.

Defined Under Namespace

Classes: ThreadPool

Instance Method Summary collapse

Constructor Details

#initialize(pool_size = 2, logger = Bob.logger) ⇒ Threaded

The optional pool size controls how many threads will be created.



9
10
11
12
# File 'lib/bob/engine/threaded.rb', line 9

def initialize(pool_size = 2, logger = Bob.logger)
  @pool   = ThreadPool.new(pool_size, logger)
  @logger = logger
end

Instance Method Details

#call(job) ⇒ Object

Adds a job to the queue.



15
16
17
# File 'lib/bob/engine/threaded.rb', line 15

def call(job)
  @pool << job
end

#njobsObject

The number of jobs currently in the queue.



20
21
22
# File 'lib/bob/engine/threaded.rb', line 20

def njobs
  @pool.njobs
end

#wait!Object

This method will not return until #njobs returns 0.



25
26
27
# File 'lib/bob/engine/threaded.rb', line 25

def wait!
  Thread.pass until @pool.njobs == 0
end