free_mutant/lib/mutant/actor/mailbox.rb
2015-11-15 23:13:43 +00:00

32 lines
723 B
Ruby

module Mutant
module Actor
# Unbound mailbox
class Mailbox
include Adamantium::Flat, Concord::Public.new(:receiver, :sender)
# New mailbox
#
# @return [Mailbox]
def self.new
mutex = Mutex.new
condition_variable = ConditionVariable.new
messages = []
super(
Receiver.new(condition_variable, mutex, messages),
Sender.new(condition_variable, mutex, messages)
)
end
# Binding for RPC to other actors
#
# @param [Actor::Sender] other
#
# @return [Binding]
def bind(other)
Binding.new(self, other)
end
end # Mailbox
end # Actor
end # Mutant