class XfOOrth::XfOOrth_Fiber
The fOOrth Fiber class.
Constants
- ALIVE
Tag for running fibers.
- DEAD
Tag for defunct fibers.
- NEW
Tag for newly created fibers.
Public Class Methods
new(&block)
click to toggle source
Build up the fiber instance. A fiber is a light-weight coroutine.
# 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
Public Instance Methods
status()
click to toggle source
What is the status of this fiber?
# File lib/fOOrth/library/fiber_library.rb, line 34 def status @status || DEAD end
step(vm)
click to toggle source
Let the fiber run for one step.
Endemic Code Smells
-
:reek:DuplicateMethodCall
# 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()
click to toggle source
Return this fiber as a fiber.
# File lib/fOOrth/library/fiber_library.rb, line 29 def to_foorth_fiber self end
yield()
click to toggle source
Yield back to the thread.
Endemic Code Smells
-
:reek:UtilityFunction
# File lib/fOOrth/library/fiber_library.rb, line 53 def yield Fiber.yield(ALIVE) end
yield_value(value)
click to toggle source
Yield a value back to the thread.
# File lib/fOOrth/library/fiber_library.rb, line 58 def yield_value(value) @save << value Fiber.yield(ALIVE) end