Class: Bob::BackgroundEngines::Threaded

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

Defined Under Namespace

Classes: ThreadPool

Instance Method Summary collapse

Constructor Details

#initialize(pool_size = 2) ⇒ Threaded

Returns a new instance of Threaded.



7
8
9
# File 'lib/bob/background_engines/threaded.rb', line 7

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

Instance Method Details

#call(job) ⇒ Object



11
12
13
# File 'lib/bob/background_engines/threaded.rb', line 11

def call(job)
  @pool << job
end

#njobsObject



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

def njobs
  @pool.njobs
end

#wait!Object



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

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