Class: Ninja::Threaded

Inherits:
Object
  • Object
show all
Defined in:
lib/ninja/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) ⇒ Threaded

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



9
10
11
# File 'lib/ninja/threaded.rb', line 9

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

Instance Method Details

#call(job) ⇒ Object

Adds a job to the queue.



14
15
16
# File 'lib/ninja/threaded.rb', line 14

def call(job)
  @pool << job
end

#njobsObject

The number of jobs currently in the queue.



19
20
21
# File 'lib/ninja/threaded.rb', line 19

def njobs
  @pool.njobs
end

#wait!Object

This method will not return until #njobs returns 0.



24
25
26
# File 'lib/ninja/threaded.rb', line 24

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