Created
March 16, 2018 09:48
-
-
Save CremboC/611664bd7a7b7f396c3b6db1a6eedee6 to your computer and use it in GitHub Desktop.
This file contains 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
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