Skip to content

Instantly share code, notes, and snippets.

@kamilkloch
Created September 15, 2023 10:26
Show Gist options
  • Save kamilkloch/064ef5e8e3d09f082421fd664dbccca5 to your computer and use it in GitHub Desktop.
Save kamilkloch/064ef5e8e3d09f082421fd664dbccca5 to your computer and use it in GitHub Desktop.
DispatcherSequential vs IO
object KKResearchDispatcherSequentialVsIO extends IOApp.Simple {
val n = 1000_000
val tasks = ArraySeq.fill(n)(IO.unit)
def run: IO[Unit] = {
val viaDispatcher = Dispatcher.sequential[IO](await = true).use { dispatcher =>
IO(tasks.foreach(dispatcher.unsafeRunAndForget))
}
val withinIORuntime = tasks.parSequence_
//viaDispatcher.timed.map(_._1.toMillis).flatMap(IO.println).foreverM
withinIORuntime.timed.map(_._1.toMillis).flatMap(IO.println).foreverM
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment