Last active
February 12, 2019 09:58
-
-
Save alkagin/68ba076636d4aa594d20d313546d1b93 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 java.util.concurrent.atomic.AtomicInteger | |
import cats._ | |
import cats.effect._ | |
import cats.effect.implicits._ | |
object foo extends IOApp { | |
import fs2._ | |
val ai = new AtomicInteger() | |
override def run(args: List[String]): IO[ExitCode] = | |
Stream(1, 2, 3, 4, 5, 6) | |
.broadcast[IO] | |
.parEvalMap(4) { s => | |
val index = ai.getAndIncrement() | |
s.evalMap(x => IO(Console.println(s"$index $x"))).compile.drain | |
} | |
.compile | |
.drain | |
.redeem(_ => ExitCode.Error, _ => ExitCode.Success) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment