Skip to content

Instantly share code, notes, and snippets.

@Yotamho
Created November 10, 2020 14:05
Show Gist options
  • Select an option

  • Save Yotamho/a903e042c4265c72b5b6904ef105fbc1 to your computer and use it in GitHub Desktop.

Select an option

Save Yotamho/a903e042c4265c72b5b6904ef105fbc1 to your computer and use it in GitHub Desktop.
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