Class: Ruck::Shreduler
Direct Known Subclasses
Instance Attribute Summary collapse
-
#current_shred ⇒ Object
readonly
Returns the value of attribute current_shred.
-
#now ⇒ Object
readonly
Returns the value of attribute now.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#shreds ⇒ Object
readonly
Returns the value of attribute shreds.
Instance Method Summary collapse
-
#initialize ⇒ Shreduler
constructor
A new instance of Shreduler.
- #invoke_shred(shred) ⇒ Object
- #next_shred ⇒ Object
- #remove_shred(shred) ⇒ Object
-
#run ⇒ Object
ruck main loop executes all shreds and synthesizes audio until all shreds exit.
-
#run_one ⇒ Object
invokes the next shred, simulates to the new VM time, then returns.
-
#sim_to(new_now) ⇒ Object
called when shreds allow time to pass a convnient method to override.
- #spork(name = "", &shred) ⇒ Object
Constructor Details
#initialize ⇒ Shreduler
Returns a new instance of Shreduler.
63 64 65 66 67 |
# File 'lib/ruck/shreduling.rb', line 63 def initialize @shreds = [] @now = 0 @running = false end |
Instance Attribute Details
#current_shred ⇒ Object (readonly)
Returns the value of attribute current_shred.
59 60 61 |
# File 'lib/ruck/shreduling.rb', line 59 def current_shred @current_shred end |
#now ⇒ Object (readonly)
Returns the value of attribute now.
61 62 63 |
# File 'lib/ruck/shreduling.rb', line 61 def now @now end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
58 59 60 |
# File 'lib/ruck/shreduling.rb', line 58 def running @running end |
#shreds ⇒ Object (readonly)
Returns the value of attribute shreds.
60 61 62 |
# File 'lib/ruck/shreduling.rb', line 60 def shreds @shreds end |
Instance Method Details
#invoke_shred(shred) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/ruck/shreduling.rb', line 90 def invoke_shred(shred) # execute shred, saving this as the resume point LOG.debug "resuming shred #{@current_shred} at #{now}" @current_shred = shred callcc { |cont| @current_shred.go(cont) } LOG.debug "back to run loop" end |
#next_shred ⇒ Object
80 81 82 |
# File 'lib/ruck/shreduling.rb', line 80 def next_shred @shreds.min # furthest behind (Shred#<=> uses Shred's current time) end |
#remove_shred(shred) ⇒ Object
75 76 77 78 |
# File 'lib/ruck/shreduling.rb', line 75 def remove_shred(shred) LOG.debug "Removing shred \"#{name}\" at #{@now}" @shreds.delete shred end |
#run ⇒ Object
ruck main loop executes all shreds and synthesizes audio
until all shreds exit
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ruck/shreduling.rb', line 115 def run LOG.debug "shreduler starting" @running = true while @shreds.length > 0 run_one end @running = false end |
#run_one ⇒ Object
invokes the next shred, simulates to the new VM time, then returns
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ruck/shreduling.rb', line 99 def run_one shred = next_shred sim_to(shred.now) invoke_shred shred if @current_shred.finished LOG.debug "#{shred} finished" @shreds.delete(shred) end end |
#sim_to(new_now) ⇒ Object
called when shreds allow time to pass a convnient method to override
86 87 88 |
# File 'lib/ruck/shreduling.rb', line 86 def sim_to(new_now) @now = new_now end |