Skip to content

Instantly share code, notes, and snippets.

@gchudnov
Created December 31, 2019 11:17
Show Gist options
  • Save gchudnov/638a7d49ee5161f9054fff2183a1c37c to your computer and use it in GitHub Desktop.
Save gchudnov/638a7d49ee5161f9054fff2183a1c37c to your computer and use it in GitHub Desktop.
package gc.demo
import com.typesafe.scalalogging.LazyLogging
import zio._
import zio.stream._
object Zio2App extends App with LazyLogging {
override def run(args: List[String]): ZIO[ZEnv, Nothing, Int] = {
Stream("a", "b", "c")
.map(it => Either.cond(it == "a", it, new RuntimeException("invalid key")))
.mapMParUnordered(4)(it => ZIO.fromEither(it))
.run(Sink.drain)
.foldM(
e => {
ZIO.effectTotal(logger.error("Application failed", e)) *> ZIO.succeed(1)
},
_ => {
ZIO.succeed(0)
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment