Class: Actor::Scheduler
- Inherits:
-
Object
- Object
- Actor::Scheduler
- Defined in:
- lib/revactor/scheduler.rb
Overview
The Actor Scheduler maintains a run queue of actors with outstanding messages who have not yet processed their mailbox. If all actors have processed their mailboxes then the scheduler waits for any outstanding Rev events. If there are no active Rev watchers then the scheduler exits.
Defined Under Namespace
Classes: Mailbox
Instance Attribute Summary collapse
-
#mailbox ⇒ Object
readonly
Returns the value of attribute mailbox.
Instance Method Summary collapse
-
#<<(actor) ⇒ Object
Schedule an Actor to be executed, and run the scheduler if it isn’t currently running.
-
#initialize ⇒ Scheduler
constructor
A new instance of Scheduler.
-
#running? ⇒ Boolean
Is the scheduler running?.
Constructor Details
Instance Attribute Details
#mailbox ⇒ Object (readonly)
Returns the value of attribute mailbox.
15 16 17 |
# File 'lib/revactor/scheduler.rb', line 15 def mailbox @mailbox end |
Instance Method Details
#<<(actor) ⇒ Object
Schedule an Actor to be executed, and run the scheduler if it isn’t currently running
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/revactor/scheduler.rb', line 26 def <<(actor) raise ArgumentError, "must be an Actor" unless actor.is_a? Actor @queue << actor unless @queue.last == actor unless @running # Reschedule the current Actor for execution @queue << Actor.current # Start the scheduler Fiber.new { run }.resume end end |
#running? ⇒ Boolean
Is the scheduler running?
41 |
# File 'lib/revactor/scheduler.rb', line 41 def running?; @running; end |