2014-10-23 07:37:53 -04:00
|
|
|
module Mutant
|
|
|
|
module Actor
|
|
|
|
|
|
|
|
# Sender for messages to acting thread
|
|
|
|
class Sender
|
2014-12-05 23:34:04 -05:00
|
|
|
include Adamantium::Flat, Concord.new(:condition_variable, :mutex, :messages)
|
2014-10-23 07:37:53 -04:00
|
|
|
|
|
|
|
# Send a message to actor
|
|
|
|
#
|
|
|
|
# @param [Object] message
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def call(message)
|
|
|
|
mutex.synchronize do
|
2014-12-05 23:34:04 -05:00
|
|
|
messages << message
|
|
|
|
condition_variable.signal
|
2014-10-23 07:37:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
end # Sender
|
|
|
|
end # Actor
|
|
|
|
end # Mutant
|