Sha256: 62f753b3f42482e9e296071a94b3ab42c394b766c45428a66d59c3e1daf8bee4

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 Bytes

Contents

module Actors
  class Actor
    attr_reader :name

    def initialize(name, executable, publishes_to: [])
      raise ArgumentError, "'name' should be an instance of Symbol" unless name.instance_of? Symbol
      raise ArgumentError, "'executable' should be a lambda"        unless executable.instance_of?(Proc) && executable.lambda?
      raise ArgumentError, "'executable' should have arity = 1"     unless executable.arity == 1

      @name       = name
      @executable = executable
      @channels   = publishes_to
    end

    def call(message)
      raise ArgumentError, "'message' should be an instance of Hash" unless message.instance_of? Hash

      result = @executable.call(message)
      @channels.each { |channel| channel.publish result }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
actors-0.1.0 lib/actors/actor.rb