Skip to content

Instantly share code, notes, and snippets.

@chenharryhua
Created December 2, 2024 07:47
Show Gist options
  • Select an option

  • Save chenharryhua/45eb8d4bfdce2d1b88ff7c75dfbf039e to your computer and use it in GitHub Desktop.

Select an option

Save chenharryhua/45eb8d4bfdce2d1b88ff7c75dfbf039e to your computer and use it in GitHub Desktop.
dispatcher
test("dispatcher.parallel") {
val a1 = IO.println("a1 start") >> IO.sleep(3.seconds) >> IO.println("a1 done")
val a2 = IO.println("a2 start") >> IO.sleep(1.seconds) >> IO.println("a2 done")
Dispatcher.parallel[IO].use { dispatcher =>
IO {
dispatcher.unsafeRunAndForget(a1)
dispatcher.unsafeRunAndForget(a2)
} >> IO.sleep(5.seconds)
}.unsafeRunSync()
}
// print
a2 start
a1 start
a2 done
a1 done
test("dispatcher.sequential") {
val a1 = IO.println("a1 start") >> IO.sleep(3.seconds) >> IO.println("a1 done")
val a2 = IO.println("a2 start") >> IO.sleep(1.seconds) >> IO.println("a2 done")
Dispatcher.sequential[IO].use { dispatcher =>
IO {
dispatcher.unsafeRunAndForget(a1)
dispatcher.unsafeRunAndForget(a2)
} >> IO.sleep(5.seconds)
}.unsafeRunSync()
}
// print
a1 start
a1 done
a2 start
a2 done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment