Bird
0
0

Identify the error in this Fiber code:

medium📝 Debug Q6 of 15
Ruby - Concurrent Programming
Identify the error in this Fiber code:
fiber = Fiber.new do
  puts 'Start'
  Fiber.yield
  puts 'End'
end
fiber.resume
fiber.resume
fiber.resume
AFiber cannot print inside its block
BFiber.yield cannot be called inside Fiber
CFiber must be resumed with an argument
DCalling resume after Fiber is finished raises FiberError
Step-by-Step Solution
Solution:
  1. Step 1: Understand Fiber lifecycle

    Fiber runs until no more code; after finishing, calling resume again causes error.
  2. Step 2: Analyze code calls

    Third resume call happens after Fiber finished, causing FiberError.
  3. Final Answer:

    Calling resume after Fiber is finished raises FiberError -> Option D
  4. Quick Check:

    Extra resume after finish = FiberError [OK]
Quick Trick: Do not resume a finished Fiber; it raises FiberError [OK]
Common Mistakes:
  • Thinking Fiber.yield is invalid
  • Assuming resume needs argument always
  • Believing Fiber can't print

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes