Class: RactorPool::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/ractor_pool/pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(jobs:, mapper_class:, reducer_class: RactorPool::Reducers::CollectReducer) ⇒ Pool

Returns a new instance of Pool.



4
5
6
7
8
9
# File 'lib/ractor_pool/pool.rb', line 4

def initialize(jobs:, mapper_class:, reducer_class: RactorPool::Reducers::CollectReducer)
  @jobs = jobs
  @logger = Logger.new($stdout)
  @mapper_class = mapper_class
  @reducer_class = reducer_class
end

Instance Method Details

#schedule(*args, **params) ⇒ Object



17
18
19
20
# File 'lib/ractor_pool/pool.rb', line 17

def schedule(*args, **params)
  jobs_pipe << { type: :job, args: args, params: params }
  self
end

#startObject



11
12
13
14
15
# File 'lib/ractor_pool/pool.rb', line 11

def start
  reducer
  workers
  self
end

#stopObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ractor_pool/pool.rb', line 22

def stop
  jobs_pipe.close!
  workers.each(&:take)
  results_pipe.close!
  result = reducer.take
  instance_variable_set(:@jobs_pipe, nil)
  instance_variable_set(:@resuts_pipe, nil)
  instance_variable_set(:@workers, nil)
  instance_variable_set(:@reducer, nil)
  result
end