Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:23
Show Gist options
  • Select an option

  • Save dacr/ffceacf56a63bc4089e7ba7433b1773f to your computer and use it in GitHub Desktop.

Select an option

Save dacr/ffceacf56a63bc4089e7ba7433b1773f to your computer and use it in GitHub Desktop.
ZIO learning - fiber based concurrency model - using fork and join / published by https://github.com/dacr/code-examples-manager #9b586f61-3106-467f-b35e-75910cf36d88/22c5c44b22a55544cfd0fe4d97e8775939d4abbe
// summary : ZIO learning - fiber based concurrency model - using fork and join
// keywords : scala, zio, learning, pure-functional, @testable
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : 9b586f61-3106-467f-b35e-75910cf36d88
// created-on : 2021-04-02T15:36:11+02:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.4.2"
//> using dep "dev.zio::zio:2.0.13"
// ---------------------
import zio.*
object ThatApp extends ZIOAppDefault {
// using fork & join - semantically block but never block underlying threads
val logic1 = for {
_ <- Console.printLine("hello")
} yield ()
val logic2 = for {
_ <- Console.printLine("world")
} yield ()
val run = for {
a <- logic1.repeat(Schedule.recurs(5) && Schedule.spaced(50.millis)).fork
b <- logic2.repeat(Schedule.recurs(5) && Schedule.spaced(50.millis)).fork
_ <- a.join // because we don't want to exit before completion ;)
_ <- b.join // because we don't want to exit before completion ;)
} yield ()
}
// -------------------------------------------------------------
ThatApp.main(Array.empty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment