Created
December 31, 2019 11:17
-
-
Save gchudnov/638a7d49ee5161f9054fff2183a1c37c 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
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