Sha256: 8e0a0ee75bb52255ec49946b4b5f795ed4d167bdf8b134f138977877e976dcf8
Contents?: true
Size: 1.27 KB
Versions: 7
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true module Mutant # A minimal actor implementation module Actor # Error raised when actor signalling protocol is violated class ProtocolError < RuntimeError end # ProtocolError # Undefined message payload Undefined = Class.new do INSPECT = 'Mutant::Actor::Undefined'.freeze # Object inspection # # @return [String] def inspect INSPECT end end.new # Message being exchanged between actors class Message include Concord::Public.new(:type, :payload) # New message # # @param [Symbol] type # @param [Object] payload # # @return [Message] def self.new(_type, _payload = Undefined) super end end # Message # Binding to other actors sender for simple RPC class Binding include Concord.new(:mailbox, :other) # Send message and wait for reply # # @param [Symbol] type # # @return [Object] def call(type) other.call(Message.new(type, mailbox.sender)) message = mailbox.receiver.call fail ProtocolError, "Expected #{type} but got #{message.type}" unless type.equal?(message.type) message.payload end end # Binding end # Actor end # Mutant
Version data entries
7 entries across 7 versions & 1 rubygems