free_mutant/lib/mutant/actor/mailbox.rb

37 lines
781 B
Ruby
Raw Normal View History

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