free_mutant/lib/mutant/actor/env.rb

32 lines
527 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-09-12 13:15:43 +00:00
2014-10-23 11:37:53 +00:00
module Mutant
module Actor
# Actor root environment
class Env
include Concord.new(:thread_root)
# Spawn a new actor executing block
#
# @return [Actor::Sender]
def spawn
mailbox = new_mailbox
2014-10-23 11:37:53 +00:00
thread_root.new do
yield mailbox
2014-10-23 11:37:53 +00:00
end
mailbox.sender
2014-10-23 11:37:53 +00:00
end
# New unbound mailbox
2014-10-23 11:37:53 +00:00
#
# @return [Mailbox]
def new_mailbox
Mailbox.new
2014-10-23 11:37:53 +00:00
end
end # Env
end # Actor
end # Mutant