Created
September 15, 2023 10:26
-
-
Save kamilkloch/064ef5e8e3d09f082421fd664dbccca5 to your computer and use it in GitHub Desktop.
DispatcherSequential vs IO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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