Build a cooperative Ruby fiber scheduler

8 steps · about 2 h 32 min · Intermediate

  1. Learn the Fiber lifecycle (reference, Ruby documentation, 20 min)

    The core class defines creation, transfer, resumption and the states a scheduler must respect.

  2. Map the scheduler interface (reference, Ruby documentation, 24 min)

    The interface lists the hooks Ruby uses to delegate blocking operations to a scheduler.

  3. Represent nonblocking I/O work (reference, Ruby documentation, 20 min)

    IO methods and readiness behaviour provide the concrete operations the scheduler coordinates.

  4. Manage buffers at nonblocking boundaries (reference, Ruby documentation, 14 min)

    IO::Buffer exposes the storage and readiness concerns used by modern scheduler-aware I/O.

  5. Handle waits without freezing all work (reference, Ruby documentation, 16 min)

    Process waits are another blocking boundary a complete scheduler must understand or reject explicitly.

  6. Contrast cooperative fibers with threads (reference, Ruby documentation, 18 min)

    Threads have different scheduling, synchronisation and failure characteristics that should not be attributed to fibers.

  7. Separate scheduling from parallel isolation (reference, Ruby documentation, 18 min)

    Ractors solve an isolation and parallelism problem rather than acting as drop-in fiber tasks.

  8. Test ordering, failure and cancellation (reference, Ruby documentation, 22 min)

    Explicit exception handling helps tests prove progress, failure propagation, cancelled waits and cleanup at shutdown.