Scala with ZIO: Introduction to Fibers

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.พ. 2025
  • Written version: blog.rockthejv...
    Compare this with Cats Effect Fibers: • Cats Effect 3: Introdu...
    This video is a quick dive into ZIO and the effect pattern. We're going to model synchronous and asynchronous computations on top of lightweight threads, aka fibers. Both Scala 2.13 and Scala 3 are identically applicable for this video. We discuss
    how to run ZIO instances sequentially, on the same thread
    how to create a Fiber via fork
    how to wait for a Fiber to finish via join
    how to interrupt Fibers
    how to make Fibers ignore interruption signals
    Follow Rock the JVM on:
    LinkedIn: / rockthejvm
    Twitter: / rockthejvm
    Blog: blog.rockthejv...
    -------------------------------------------------------------------------
    Home: rockthejvm.com
    -------------------------------------------------------------------------

ความคิดเห็น • 36

  • @theyreMineralsMarie
    @theyreMineralsMarie 3 ปีที่แล้ว +6

    This is such a nice abstraction for concurrency. I use Project Reactor as part of Spring WebFlux at work and wish it had some of the lower level control that ZIO appears to give you. I like that it blends the concepts of threads found in C with the expressiveness of functional programming.

  • @sherwin96
    @sherwin96 3 ปีที่แล้ว +6

    Sounds like a new zio course is on the way 😃

    • @rockthejvm
      @rockthejvm  3 ปีที่แล้ว +5

      relatively soon! 😅

  • @DiegoFerreiradaSilva
    @DiegoFerreiradaSilva 3 ปีที่แล้ว +1

    thank you and more videos about zio please!

  • @mankoxyz
    @mankoxyz 3 ปีที่แล้ว +9

    Great stuff, you should do more videos on ZIO.

  • @Sando816
    @Sando816 2 ปีที่แล้ว +1

    Thank you very much to share!

  • @thajafsal
    @thajafsal 3 ปีที่แล้ว +1

    Zio is just so useful and easy.

  • @rafaeldelgado7860
    @rafaeldelgado7860 3 ปีที่แล้ว +3

    Great video! Thank you! It would be great if you could make more with ZIO. ZIO rocks!

  • @GVLPedro
    @GVLPedro 3 ปีที่แล้ว +2

    Hi Daniel, we want more about ZIO !! I think ZIO 2 is available and it is faster than version 1, maybe it is a good point to continue... thanks a lot!!

    • @rockthejvm
      @rockthejvm  3 ปีที่แล้ว

      Will do! ZIO 2.0 is close to RC, will have more content out as soon as it becomes stable.

  • @rk-fx9wc
    @rk-fx9wc 2 ปีที่แล้ว +1

    Absoultely awesome video, thank you so much! Do you consider to record a video about the Error handling in ZIO? It'd be so great!

    • @rockthejvm
      @rockthejvm  2 ปีที่แล้ว +1

      Good idea - might do a video there

  • @HoD999x
    @HoD999x ปีที่แล้ว

    but interrupt doesn't stop an already running process, it just prevents the jump to the next step, right?

    • @rockthejvm
      @rockthejvm  ปีที่แล้ว

      Yes - there is a way of stopping the thread itself via thread interrupts, but that mechanism is nasty.

  • @shishe1984
    @shishe1984 3 ปีที่แล้ว

    I love how you explained all of this. I still have one question though: is there a criteria on how the fibers get dispatched to the execution context? With other frameworks such as Play, you could have different execution contexts, and then you could explicitly move the spawned threads/futures to the corresponding context as to avoid blocking certain parts of the application with them. Do fibers follow a similiar philosophy?

    • @rockthejvm
      @rockthejvm  3 ปีที่แล้ว

      It's certainly possible.

  • @kyotin1
    @kyotin1 3 ปีที่แล้ว

    Awesome video!

  • @imranfp
    @imranfp 3 ปีที่แล้ว +2

    You really rocks :) but being a viewer I would expect, if you could also explain the concept with visual examples, as you have mentioned in your few videos about Actors. Overall, waiting for your "Functional Programming Concept", "ZIO", "Cats Effect 3" and "Functional Micro services" courses.

    • @rockthejvm
      @rockthejvm  3 ปีที่แล้ว +5

      visual explanations & diagrams take a lot of work - you can expect them in the courses :D

  • @alexandrutudor6195
    @alexandrutudor6195 3 ปีที่แล้ว +1

    By this video, I can understant that scala Futures will be deprecated in exchange for ZIO? I'm a bit confused and hope I'm not wrong, but you can use Futures very easily for concurrent programming :d Why I would use ZIO, a new library instead of the benefits of the language? Or, this is really a FP concept (how somebody said below). thx

    • @rockthejvm
      @rockthejvm  3 ปีที่แล้ว

      Scala Futures aren't going anywhere. ZIO was invented to 1) avoid callback-based concurrent applications ("callback hell"), 2) simplify Scala code, 3) avoid unnecessary abstractions (e.g. overdoing tagless final)

  • @lac4793
    @lac4793 3 ปีที่แล้ว

    Thanks, Daniel, this video is absolutely incredible. I'm wondering if, There are other reasons besides the reasonable low cost of canceling a running fiber (thread) to use fiber instead of normal thread?

    • @rockthejvm
      @rockthejvm  3 ปีที่แล้ว

      Glad to hear you liked it! The fact that fibers are cheap and small is the main reason why we should use them.

  • @iFunktion
    @iFunktion 2 ปีที่แล้ว

    I'm guessing this is an old tutorial, intellij is asking to implement environmentalTag and bootstrap? And won't run properly without them, what does this mean?

    • @iFunktion
      @iFunktion 2 ปีที่แล้ว +1

      Solved it, with "object ZioFibers extends zio.ZIOAppDefault" That covers the overrides it seems :)

  • @miguelguzman8217
    @miguelguzman8217 3 ปีที่แล้ว

    Hey love your videos! They've helped me several times however I find them a little to abstract sometimes. For example it is not clear to me how can I consume the result of the fibers, I might want to send information to two databases (one on postgres and another on oracle) at the same time, but how can I know when both fibers have completed and how can I report to console or logs if the operations succeeded? Or maybe fibers can only do side-effects and are not effective to return any information and perform an action on the information?
    Keep up the good work!

    • @rockthejvm
      @rockthejvm  3 ปีที่แล้ว +1

      There are many combinators that work with the results of fibers - probably a topic for a future video

    • @miguelguzman8217
      @miguelguzman8217 3 ปีที่แล้ว

      Cool!
      Thanks for taking the time to make great content like this! Looking forward for your next videos.

  • @BloodnutXcom
    @BloodnutXcom 3 ปีที่แล้ว +1

    The U in UIO means Uninterruptible because it can't fail (E is Nothing)

    • @rockthejvm
      @rockthejvm  3 ปีที่แล้ว

      I forgot where names came from - thanks!

    • @angelooparah4223
      @angelooparah4223 3 ปีที่แล้ว +3

      It actually stands for Unexceptional (for that reason: it cannot fail)

    • @BloodnutXcom
      @BloodnutXcom 3 ปีที่แล้ว +1

      @@angelooparah4223 is it? Huh, my bad

  • @mayonesacosmica
    @mayonesacosmica 3 ปีที่แล้ว +1

    somebody has some quantum influence