Skip to content

Instantly share code, notes, and snippets.

@CremboC
Created March 16, 2018 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CremboC/611664bd7a7b7f396c3b6db1a6eedee6 to your computer and use it in GitHub Desktop.
Save CremboC/611664bd7a7b7f396c3b6db1a6eedee6 to your computer and use it in GitHub Desktop.
import $ivy.`org.typelevel::cats-core:1.0.1`
import $ivy.`org.typelevel::cats-effect:0.9`
import cats.effect.IO
import cats.implicits._
def f(s: String) = IO { Thread.sleep(1000); s }
def timeIO[A](f: IO[A]): A = {
val start = System.nanoTime
val result = f.unsafeRunSync()
println(s"Time: ${System.nanoTime - start}")
result
}
timeIO((f("hi"), f("bye")).parMapN((a, b) => println(a,b))) // takes 2 seconds~
timeIO((f("1"), f("2"), f("3")).parMapN((a, b, c) => println(a,b, c))) // takes 3 seconds~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment