2014-10-23 07:37:53 -04:00
|
|
|
module Mutant
|
|
|
|
module Actor
|
|
|
|
# Actor root environment
|
|
|
|
class Env
|
|
|
|
include Concord.new(:thread_root)
|
|
|
|
|
|
|
|
# Spawn a new actor executing block
|
|
|
|
#
|
|
|
|
# @return [Actor::Sender]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def spawn
|
2014-12-05 23:34:04 -05:00
|
|
|
mailbox = new_mailbox
|
2014-10-23 07:37:53 -04:00
|
|
|
|
2014-12-05 23:34:04 -05:00
|
|
|
thread_root.new do
|
|
|
|
yield mailbox
|
2014-10-23 07:37:53 -04:00
|
|
|
end
|
|
|
|
|
2014-12-05 23:34:04 -05:00
|
|
|
mailbox.sender
|
2014-10-23 07:37:53 -04:00
|
|
|
end
|
|
|
|
|
2014-12-05 23:34:04 -05:00
|
|
|
# Return new unbound mailbox
|
2014-10-23 07:37:53 -04:00
|
|
|
#
|
2014-12-05 23:34:04 -05:00
|
|
|
# @return [Mailbox]
|
2014-10-23 07:37:53 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-12-05 23:34:04 -05:00
|
|
|
def new_mailbox
|
|
|
|
Mailbox.new
|
2014-10-23 07:37:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end # Env
|
|
|
|
end # Actor
|
|
|
|
end # Mutant
|