Class: CSP::Scheduler
- Inherits:
-
Object
- Object
- CSP::Scheduler
- Defined in:
- lib/csp/scheduler.rb
Instance Method Summary collapse
- #enqueue(cont) ⇒ Object
-
#initialize ⇒ Scheduler
constructor
A new instance of Scheduler.
- #run ⇒ Object
- #schedule ⇒ Object
- #yield ⇒ Object
Constructor Details
#initialize ⇒ Scheduler
Returns a new instance of Scheduler.
6 7 8 |
# File 'lib/csp/scheduler.rb', line 6 def initialize @ready = [] end |
Instance Method Details
#enqueue(cont) ⇒ Object
10 11 12 |
# File 'lib/csp/scheduler.rb', line 10 def enqueue(cont) @ready << cont end |
#run ⇒ Object
14 15 16 |
# File 'lib/csp/scheduler.rb', line 14 def run schedule until @ready.empty? end |
#schedule ⇒ Object
25 26 27 28 |
# File 'lib/csp/scheduler.rb', line 25 def schedule raise RuntimeError.new("Cannot yield; ready queue is empty") if @ready.empty? @ready.shift.call end |
#yield ⇒ Object
18 19 20 21 22 23 |
# File 'lib/csp/scheduler.rb', line 18 def yield callcc do |cont| enqueue(cont) run end end |