Fiber for cooperative concurrency
📖 Scenario: You are building a simple program that uses Ruby Fiber to switch between two tasks cooperatively. This simulates how two workers take turns doing their jobs without interrupting each other.
🎯 Goal: Create two Fiber objects that print messages in turns, showing how cooperative concurrency works with Fiber.yield and Fiber.resume.
📋 What You'll Learn
Create two Fiber objects named
fiber1 and fiber2.Each fiber should print a message and then yield control.
Use a loop to resume each fiber alternately two times.
Print the messages exactly as specified.
💡 Why This Matters
🌍 Real World
Fibers let programs switch between tasks without waiting for one to finish, useful in games, network servers, or UI where tasks share time smoothly.
💼 Career
Understanding fibers helps in writing efficient Ruby programs that handle multiple tasks cooperatively, improving responsiveness and resource use.
Progress0 / 4 steps