Class: Concurrent::Actor::Utils::Pool
- Inherits:
-
RestartingContext
- Object
- AbstractContext
- RestartingContext
- Concurrent::Actor::Utils::Pool
- Defined in:
- lib/concurrent/actor/utils/pool.rb
Overview
Allows to create a pool of workers and distribute work between them
Instance Attribute Summary (collapse)
- - (undocumented) core inherited from AbstractContext readonly
Instance Method Summary (collapse)
-
- (Pool) initialize(size, &worker_initializer)
constructor
A new instance of Pool.
- - (undocumented) on_message(message)
Constructor Details
- (Pool) initialize(size, &worker_initializer)
Returns a new instance of Pool
30 31 32 33 34 35 36 37 |
# File 'lib/concurrent/actor/utils/pool.rb', line 30 def initialize(size, &worker_initializer) @balancer = Balancer.spawn name: :balancer, supervise: true @workers = ::Array.new(size, &worker_initializer) @workers.each do |worker| Type! worker, Reference @balancer << [:subscribe, worker] end end |
Instance Attribute Details
- (undocumented) core (readonly) Originally defined in class AbstractContext
Instance Method Details
- (undocumented) on_message(message)
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/concurrent/actor/utils/pool.rb', line 39 def () command, _ = return if [:restarted, :reset, :resumed, :terminated].include? command # ignore events from supervised actors envelope_to_redirect = if envelope.future envelope else Envelope.new(envelope., Promises.resolvable_future, envelope.sender, envelope.address) end envelope_to_redirect.future.on_fulfillment! { @balancer << :subscribe } # TODO check safety of @balancer reading redirect @balancer, envelope_to_redirect end |