free_mutant/lib/mutant/actor/env.rb

36 lines
577 B
Ruby
Raw Normal View History

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
mailbox = new_mailbox
2014-10-23 07:37:53 -04:00
thread_root.new do
yield mailbox
2014-10-23 07:37:53 -04:00
end
mailbox.sender
2014-10-23 07:37:53 -04:00
end
# Return new unbound mailbox
2014-10-23 07:37:53 -04:00
#
# @return [Mailbox]
2014-10-23 07:37:53 -04:00
#
# @api private
#
def new_mailbox
Mailbox.new
2014-10-23 07:37:53 -04:00
end
end # Env
end # Actor
end # Mutant