Class: Actor::Scheduler::Mailbox

Inherits:
Rev::AsyncWatcher
  • Object
show all
Defined in:
lib/revactor/scheduler.rb

Overview

The Scheduler Mailbox allows messages to be safely delivered across threads. If a thread is sleeping sending it a message will wake it up.

Instance Method Summary collapse

Constructor Details

#initializeMailbox

Returns a new instance of Mailbox.



98
99
100
101
102
103
# File 'lib/revactor/scheduler.rb', line 98

def initialize
  super
  
  @queue = []
  @lock = Mutex.new
end

Instance Method Details

#send(actor, message) ⇒ Object



105
106
107
108
# File 'lib/revactor/scheduler.rb', line 105

def send(actor, message)
  @lock.synchronize { @queue << T[actor, message] }
  signal
end