Class: Proletariat::PoolableActor

Inherits:
Concurrent::Actor::Utils::AbstractWorker
  • Object
show all
Includes:
ActorCommon
Defined in:
lib/proletariat/concurrency/poolable_actor.rb

Overview

Public: Interface abstraction for a pool of Concurrent::Actor instances.

Direct Known Subclasses

Publisher, Worker

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActorCommon

included, #on_event

Class Method Details

.pool(pool_size, suffix = '') ⇒ Object



18
19
20
21
22
23
# File 'lib/proletariat/concurrency/poolable_actor.rb', line 18

def self.pool(pool_size, suffix = '')
  Concurrent::Actor::Utils::
    Pool.spawn!("#{to_s}_pool", pool_size) do |b, i|
      spawn(name: "#{to_s}_#{i}_#{suffix}", supervise: true, args: [b])
    end
end

Instance Method Details

#on_message(message) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/proletariat/concurrency/poolable_actor.rb', line 8

def on_message(message)
  if respond_to?(:work_method)
    send work_method, message
  else
    work message
  end
ensure
  @balancer << :subscribe
end