Sha256: 04af38012162f09f76b1a1ce79bbd333e12aee67321be7df190bc479062281fb

Contents?: true

Size: 661 Bytes

Versions: 3

Compression:

Stored size: 661 Bytes

Contents

require 'proletariat/concurrency/actor_common'

module Proletariat
  # Public: Interface abstraction for a pool of Concurrent::Actor instances.
  class PoolableActor < Concurrent::Actor::Utils::AbstractWorker
    include ActorCommon

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

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
proletariat-0.1.2 lib/proletariat/concurrency/poolable_actor.rb
proletariat-0.1.1 lib/proletariat/concurrency/poolable_actor.rb
proletariat-0.1.0 lib/proletariat/concurrency/poolable_actor.rb