Class: Prole

Inherits:
Object
  • Object
show all
Defined in:
lib/prole.rb,
lib/prole/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(threads: 10, logger: nil) ⇒ Prole

Returns a new instance of Prole.



5
6
7
8
9
10
11
12
# File 'lib/prole.rb', line 5

def initialize(threads: 10, logger: nil)
  @thread_count = threads
  @thread_pool = []
  @jobs = []
  @thread_count.times do
    @thread_pool << ProleWorker.new(@jobs, logger: logger)
  end
end

Instance Method Details

#add_job(proc = nil, &block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/prole.rb', line 14

def add_job(proc = nil, &block)
  if block_given?
    @jobs << (Proc.new &block)
  elsif proc.is_a?(Proc)
    @jobs << proc
  end
end

#joinObject



22
23
24
# File 'lib/prole.rb', line 22

def join
  @thread_pool.map &:join
end