Class: XfOOrth::XfOOrth_Bundle
- Defined in:
- lib/fOOrth/library/bundle_library.rb
Overview
The fOOrth Bundle class. A bundle contains multiple fibers.
Direct Known Subclasses
Instance Method Summary collapse
-
#add_fibers(fibers) ⇒ Object
Add the fibers to this bundle.
-
#initialize(fibers = []) ⇒ XfOOrth_Bundle
constructor
Build up the bundle instance.
-
#length ⇒ Object
how many fibers in this bundle?.
-
#run(vm) ⇒ Object
Run the fiber bundle constantly until done.
-
#status ⇒ Object
What is the status of this bundle?.
-
#step(vm) ⇒ Object
Let the fiber run for one step.
-
#to_foorth_fiber ⇒ Object
Return this bundle as a fiber.
Constructor Details
#initialize(fibers = []) ⇒ XfOOrth_Bundle
Build up the bundle instance
13 14 15 16 17 18 |
# File 'lib/fOOrth/library/bundle_library.rb', line 13 def initialize(fibers=[]) @fibers = fibers.in_array.map {|f| f.to_foorth_fiber} @current = 0 rescue NoMethodError error "F70: A bundle may only contain procedures, fibers, or bundles." end |
Instance Method Details
#add_fibers(fibers) ⇒ Object
Add the fibers to this bundle.
21 22 23 24 25 |
# File 'lib/fOOrth/library/bundle_library.rb', line 21 def add_fibers(fibers) fibers.in_array.each {|f| @fibers << f.to_foorth_fiber} rescue NoMethodError error "F70: A bundle may only contain procedures, fibers, or bundles." end |
#length ⇒ Object
how many fibers in this bundle?
38 39 40 |
# File 'lib/fOOrth/library/bundle_library.rb', line 38 def length @fibers.length end |
#run(vm) ⇒ Object
Run the fiber bundle constantly until done.
57 58 59 |
# File 'lib/fOOrth/library/bundle_library.rb', line 57 def run(vm) while step(vm); end end |
#status ⇒ Object
What is the status of this bundle?
33 34 35 |
# File 'lib/fOOrth/library/bundle_library.rb', line 33 def status @fibers.empty? ? "dead" : "alive" end |
#step(vm) ⇒ Object
Let the fiber run for one step
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fOOrth/library/bundle_library.rb', line 43 def step(vm) if @current < @fibers.length if @fibers[@current].step(vm) @current += 1 else @fibers.delete_at(@current) end end @current = 0 unless @current < @fibers.length !@fibers.empty? end |
#to_foorth_fiber ⇒ Object
Return this bundle as a fiber.
28 29 30 |
# File 'lib/fOOrth/library/bundle_library.rb', line 28 def to_foorth_fiber self end |