Bird
0
0

Identify the error in this Fiber usage:

medium📝 Debug Q14 of 15
Ruby - Concurrent Programming
Identify the error in this Fiber usage:
fiber = Fiber.new do
  puts 'Start'
  Fiber.yield
  puts 'End'
end

fiber.yield
fiber.resume
ACalling Fiber.yield outside a Fiber block causes an error
BFiber.resume must be called before Fiber.yield
CFiber.new requires a parameter for yield count
DFiber cannot print inside its block
Step-by-Step Solution
Solution:
  1. Step 1: Check where Fiber.yield is called

    The code calls fiber.yield outside the Fiber block, which is invalid.
  2. Step 2: Understand Fiber.yield usage

    Fiber.yield is a class method to pause current Fiber, not an instance method on Fiber objects.
  3. Final Answer:

    Calling Fiber.yield outside a Fiber block causes an error -> Option A
  4. Quick Check:

    Fiber.yield only inside Fiber block [OK]
Quick Trick: Fiber.yield is called inside Fiber block only [OK]
Common Mistakes:
  • Calling fiber.yield instead of Fiber.yield
  • Expecting Fiber.resume before yield call
  • Thinking Fiber.new needs parameters for yield

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes