The code is calling resume
regardless of state of the fiber.
Check whether fiber can resume by calling Fiber#alive?
def each
while @fiber.alive? do
yield self.next
end
end
NOTE You need to do require 'fiber'
to use alive?
method.
UPDATE accoridng to the question edit.
The original code yields only once. To iterate indefinitely, you need loop.
def initialize(a)
sum = a
pow = a
@fiber = Fiber.new do
loop do # <-------------
Fiber.yield sum
pow = pow * a
sum = sum + pow
end # <-----------------
end
end