Search code examples
javascalaziocats-effect

Fiber on the JVM with Scala IO implementations


My understanding is that IO Implementation like cats-effetcs or Zio use fibers, and this on the JVM.

I wonder what's the underlying lib or framework they are using, if the JVM e.g. 11 does not officially support fibers yet ?


Solution

  • The JVM has no official support for fibers. This is however in the works with Project Loom.

    In the meantime, effect libraries like ZIO and Cats Effect are maintaining a pool of thread and rolling their own thread scheduling implementation, as stated in the question comments by Luis.

    If the fact that fiber implementations are library-specific is making you think that they're a bug-risk in open-source libraries, please keep in mind the following: fibers are a low-level concept in both ZIO and Cats Effect. The point of these libraries is to largely decouple what is run from the details of exactly how it runs. They still offer flexibility for you to express how to run things, but this part of the API is not used in 90% of cases. What ZIO and Cats Effect bring you is a way to express concurrent tasks with nice type-safe primitive. This is exactly what will help you avoid bugs.