-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #470 from ScalaConsultants/ronald/463-documentation
Ticket 463 -- updated documentation && added SimpleZioExample code into the "example directory"
- Loading branch information
Showing
10 changed files
with
190 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,6 @@ target/ | |
project/project | ||
project/target | ||
project/metals.sbt | ||
.DS_Store | ||
|
||
!opentelemetry-javaagent110.jar |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package example | ||
|
||
import zio._ | ||
import zio.metrics.jvm.DefaultJvmMetrics | ||
|
||
object SimpleZioExample extends ZIOAppDefault { | ||
|
||
override def run: ZIO[Any, Throwable, Boolean] = | ||
ZioProgram | ||
.findTheMeaningOfLife(3, Int.MinValue, Int.MaxValue) | ||
.provide( | ||
Runtime.enableRuntimeMetrics, // NOTE: refactored by following this zio-metrics-connectors example ( https://github.com/zio/zio-metrics-connectors/blob/zio/series2.x/core/jvm/src/test/scala/zio/metrics/connectors/SampleApp.scala#L15-L71 ) | ||
DefaultJvmMetrics.live.unit // NOTE: DefaultJvmMetrics.live collects the same JVM metrics as the Prometheus Java client's default exporters | ||
) | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package example | ||
|
||
import zio.Console | ||
import zio.Random | ||
import zio.Schedule | ||
import zio.ZIO | ||
import zio.durationInt | ||
|
||
object ZioProgram { | ||
|
||
def findTheMeaningOfLife(parallelism: Int, lowerBound: Int, upperBound: Int): ZIO[Any, Nothing, Boolean] = { | ||
val numberToGuess = 42 | ||
|
||
val task: ZIO[Any, Nothing, Boolean] = { | ||
val recurringTask = (for { | ||
_ <- Console.printLine("Looking for the meaning of life...") | ||
guessedNumber <- Random.nextIntBetween(lowerBound, upperBound) | ||
_ <- Console.printLine(s"Found some number: $guessedNumber") *> ZIO.sleep(100.milliseconds) | ||
result = guessedNumber == numberToGuess | ||
} yield result).orDie | ||
|
||
recurringTask.repeat(Schedule.recurUntilEquals(true)) | ||
} | ||
|
||
val tasks = (0 until parallelism).map(_ => task).toList | ||
ZIO.raceAll(tasks.head, tasks.tail) | ||
} | ||
|
||
} |
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