Created
November 10, 2020 14:05
-
-
Save Yotamho/a903e042c4265c72b5b6904ef105fbc1 to your computer and use it in GitHub Desktop.
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
| package com.checkpoint.datatube.firehose | |
| import java.util.concurrent.TimeUnit | |
| import cats.effect.{Clock, ExitCode, IO, IOApp} | |
| import cats.implicits._ | |
| object CatsParallelExecution extends IOApp{ | |
| val clock: Clock[IO] = Clock[IO] | |
| override def run(args: List[String]): IO[ExitCode] = { | |
| for { | |
| start <- clock.monotonic(TimeUnit.MILLISECONDS) | |
| _ <- List( | |
| IO(Thread.sleep(5000)), | |
| IO(Thread.sleep(5000)) | |
| ).parSequence | |
| code <- clock.monotonic(TimeUnit.MILLISECONDS).map {end => | |
| println(end - start) | |
| ExitCode.Success | |
| } | |
| } yield code | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment