Class: Concurrent::Actors::Actor

Inherits:
Object
  • Object
show all
Defined in:
lib/concurrent/actors/actor.rb,
lib/concurrent/actors/mailbox.rb

Defined Under Namespace

Classes: Mailbox

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailbox) ⇒ Actor

Returns a new instance of Actor.



72
73
74
# File 'lib/concurrent/actors/actor.rb', line 72

def initialize(mailbox)
  @mailbox = mailbox
end

Class Method Details

.currentObject



58
59
60
# File 'lib/concurrent/actors/actor.rb', line 58

def current
  Thread.current[:__current_actor__] ||= private_new(current_mailbox)
end

.current_mailboxObject



62
63
64
# File 'lib/concurrent/actors/actor.rb', line 62

def current_mailbox
  Thread.current[:__current_mailbox__] ||= Mailbox.new
end

.receive(timeout = nil, &prc) ⇒ Object



67
68
69
# File 'lib/concurrent/actors/actor.rb', line 67

def receive(timeout=nil, &prc)
  current_mailbox.receive(timeout, &prc)
end

.spawn(&prc) ⇒ Object Also known as: new



48
49
50
51
52
53
54
55
# File 'lib/concurrent/actors/actor.rb', line 48

def spawn(&prc)
  channel = Core::Channel.new
  Thread.new do
    channel << current
    prc.call
  end
  channel.receive
end

Instance Method Details

#<<(value) ⇒ Object



76
77
78
79
# File 'lib/concurrent/actors/actor.rb', line 76

def <<(value)
  @mailbox << value
  self
end