Sha256: aa988b967d46cf88b8f9efdd191e377c1342b3a28fa3cd91fd1fa35679684e82

Contents?: true

Size: 565 Bytes

Versions: 2

Compression:

Stored size: 565 Bytes

Contents

module Aggro
  # Private: Wraps a given target in an concurrent actor.
  class ConcurrentActor < Concurrent::Actor::Context
    def initialize(target)
      @target = target
    end

    def on_message(message)
      if command? message
        @target.send :apply_command, message
      elsif query? message
        @target.send :run_query, message
      end
    end

    private

    def command?(message)
      message.class.included_modules.include? Command
    end

    def query?(message)
      message.class.included_modules.include? Query
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aggro-0.0.3 lib/aggro/concurrent_actor.rb
aggro-0.0.2 lib/aggro/concurrent_actor.rb