Skip to content

Instantly share code, notes, and snippets.

@alkagin
Last active February 12, 2019 09:58
Show Gist options
  • Save alkagin/68ba076636d4aa594d20d313546d1b93 to your computer and use it in GitHub Desktop.
Save alkagin/68ba076636d4aa594d20d313546d1b93 to your computer and use it in GitHub Desktop.
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