Skip to content

Commit

Permalink
Rewrite test fiber scheduler to use object_id as keys
Browse files Browse the repository at this point in the history
It turns out our current code cannot use Fiber instances as hash keys.
  • Loading branch information
herwinw committed Oct 13, 2023
1 parent c34731d commit af6f100
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions test/natalie/fiber/shared/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ def initialize

def run
until @waiting.empty?
fiber, = @waiting.find { |fiber, timeout| fiber.alive? && timeout <= current_time }
obj_id, (fiber, _) = @waiting.find { |_, (fiber, timeout)| fiber.alive? && timeout <= current_time }

unless fiber.nil?
@waiting.delete(fiber)
unless obj_id.nil?
@waiting.delete(obj_id)
fiber.resume
end
end
Expand All @@ -19,7 +19,8 @@ def close
end

def kernel_sleep(duration)
@waiting[Fiber.current] = current_time + duration
# NATFIXME: Issues when using Fiber objects as hash key, use object_id for the time being.
@waiting[Fiber.current.object_id] = [Fiber.current, current_time + duration]
Fiber.yield
end

Expand Down

0 comments on commit af6f100

Please sign in to comment.