module DragonSkeleton::LongCalculation::LongCalculationFiber
A long calculation that runs over many steps and eventually returns a result.
Attributes
result[RW]
The result of the calculation or nil
if the calculation has not finished yet.
Public Instance Methods
finish()
click to toggle source
Runs the calculation until it finishes.
# File lib/dragon_skeleton/long_calculation/long_calculation_fiber.rb, line 61 def finish self.yield_strategy = NeverYieldStrategy resume end
finished?()
click to toggle source
Returns true
if the calculation has finished.
# File lib/dragon_skeleton/long_calculation/long_calculation_fiber.rb, line 56 def finished? !result.nil? end
resume()
click to toggle source
Runs the next step of the calculation.
Calls superclass method
# File lib/dragon_skeleton/long_calculation/long_calculation_fiber.rb, line 48 def resume return if finished? self.yield_strategy ||= AlwaysYieldStrategy super end
run_for_ms(milliseconds)
click to toggle source
Runs the calculation until it finishes or the given amount of milliseconds has passed.
This is useful for spreading the calculation over multiple ticks.
# File lib/dragon_skeleton/long_calculation/long_calculation_fiber.rb, line 69 def run_for_ms(milliseconds) self.yield_strategy = YieldAfterDurationStrategy.new(milliseconds) resume end