Class: XfOOrth::XfOOrth_Fiber
- Defined in:
- lib/fOOrth/library/fiber_library.rb
Overview
The fOOrth Fiber class.
Constant Summary collapse
- NEW =
Tag for newly created fibers.
"new".freeze
- ALIVE =
Tag for running fibers.
"alive".freeze
- DEAD =
Tag for defunct fibers.
"dead".freeze
Instance Method Summary collapse
-
#initialize(&block) ⇒ XfOOrth_Fiber
constructor
Build up the fiber instance.
-
#status ⇒ Object
What is the status of this fiber?.
-
#step(vm) ⇒ Object
Let the fiber run for one step.
-
#to_foorth_fiber ⇒ Object
Return this fiber as a fiber.
-
#yield ⇒ Object
Yield back to the thread.
-
#yield_value(value) ⇒ Object
Yield a value back to the thread.
Constructor Details
#initialize(&block) ⇒ XfOOrth_Fiber
Build up the fiber instance. A fiber is a light-weight coroutine.
22 23 24 25 26 |
# File 'lib/fOOrth/library/fiber_library.rb', line 22 def initialize(&block) @stack = [] @fiber = Fiber.new &lambda{|vm| block.call(vm); nil} @status = NEW end |
Instance Method Details
#status ⇒ Object
What is the status of this fiber?
34 35 36 |
# File 'lib/fOOrth/library/fiber_library.rb', line 34 def status @status || DEAD end |
#step(vm) ⇒ Object
Let the fiber run for one step.
Endemic Code Smells
-
:reek:DuplicateMethodCall
41 42 43 44 45 46 47 48 |
# File 'lib/fOOrth/library/fiber_library.rb', line 41 def step(vm) vm.data_stack, vm.fiber, @save = @stack, self, vm.data_stack @status = @fiber.resume(vm) rescue FiberError error "F72: The fiber is dead, no further steps can be taken." ensure vm.data_stack, vm.fiber, @stack = @save, nil, vm.data_stack end |
#to_foorth_fiber ⇒ Object
Return this fiber as a fiber.
29 30 31 |
# File 'lib/fOOrth/library/fiber_library.rb', line 29 def to_foorth_fiber self end |