Class: ActiveConcurrency::Base::Pool

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

Direct Known Subclasses

Processes::Pool, Threads::Pool

Instance Method Summary collapse

Constructor Details

#initialize(size: 2, scheduler: DEFAULT_SCHEDULER, **options) ⇒ Pool

Returns a new instance of Pool.



9
10
11
12
13
# File 'lib/active_concurrency/base/pool.rb', line 9

def initialize(size: 2, scheduler: DEFAULT_SCHEDULER, **options)
  size = [size, options[:topics].size].max if options.key?(:topics)
  @pool = Array.new(size) { |n| worker.new(name: n) }
  @scheduler = scheduler.new(@pool, options)
end

Instance Method Details

#clearObject



15
16
17
# File 'lib/active_concurrency/base/pool.rb', line 15

def clear
  @pool.map(&:clear)
end

#closeObject



19
20
21
# File 'lib/active_concurrency/base/pool.rb', line 19

def close
  @pool.map(&:close)
end

#closedObject



23
24
25
26
27
# File 'lib/active_concurrency/base/pool.rb', line 23

def closed
  @pool.each_with_object({}) do |w, h|
    h[w.name] = w.closed?
  end
end

#exitObject



29
30
31
# File 'lib/active_concurrency/base/pool.rb', line 29

def exit
  @pool.map(&:exit)
end

#exit!Object



33
34
35
# File 'lib/active_concurrency/base/pool.rb', line 33

def exit!
  @pool.map(&:exit!)
end

#joinObject



41
42
43
# File 'lib/active_concurrency/base/pool.rb', line 41

def join
  @pool.map(&:join)
end

#lockObject



45
46
47
# File 'lib/active_concurrency/base/pool.rb', line 45

def lock
  @pool.map(&:lock)
end

#schedule(*args, &block) ⇒ Object



37
38
39
# File 'lib/active_concurrency/base/pool.rb', line 37

def schedule(*args, &block)
  @scheduler.schedule(*args, &block)
end

#shutdownObject



55
56
57
# File 'lib/active_concurrency/base/pool.rb', line 55

def shutdown
  @pool.map(&:shutdown)
end

#sizesObject



49
50
51
52
53
# File 'lib/active_concurrency/base/pool.rb', line 49

def sizes
  @pool.each_with_object({}) do |w, h|
    h[w.name] = w.size
  end
end

#statusesObject



59
60
61
62
63
# File 'lib/active_concurrency/base/pool.rb', line 59

def statuses
  @pool.each_with_object({}) do |w, h|
    h[w.name] = w.status
  end
end