Class: ActiveConcurrency::Base::Pool
- Inherits:
-
Object
- Object
- ActiveConcurrency::Base::Pool
show all
- Defined in:
- lib/active_concurrency/base/pool.rb
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
#clear ⇒ Object
15
16
17
|
# File 'lib/active_concurrency/base/pool.rb', line 15
def clear
@pool.map(&:clear)
end
|
#close ⇒ Object
19
20
21
|
# File 'lib/active_concurrency/base/pool.rb', line 19
def close
@pool.map(&:close)
end
|
#closed ⇒ Object
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
|
#exit ⇒ Object
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
|
#join ⇒ Object
41
42
43
|
# File 'lib/active_concurrency/base/pool.rb', line 41
def join
@pool.map(&:join)
end
|
#lock ⇒ Object
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
|
#shutdown ⇒ Object
55
56
57
|
# File 'lib/active_concurrency/base/pool.rb', line 55
def shutdown
@pool.map(&:shutdown)
end
|
#sizes ⇒ Object
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
|
#statuses ⇒ Object
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
|