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
//> using scala "2.13.14" | |
//> using dep "org.typelevel::cats-effect:3.5.4" | |
//> using dep "org.typelevel::cats-core:2.12.0" | |
import cats.effect.{IO, IOApp} | |
import cats.syntax.all._ | |
import cats.effect.kernel.syntax.all._ | |
import cats.effect.kernel.GenConcurrent | |
import cats.effect.kernel.Deferred |
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
//> using scala "2.13.11" | |
//> using lib "org.typelevel::cats-effect:3.5.1" | |
import java.lang.management.ManagementFactory | |
import javax.management.ObjectName | |
import javax.management.Query | |
import scala.collection.JavaConverters.asScalaSetConverter | |
import javax.management.MBeanServer |
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
//> using lib "co.fs2::fs2-core:3.5.0" | |
//> using lib "org.typelevel::cats-effect:3.4.6" | |
import cats.effect.{IO, IOApp} | |
import fs2.Stream | |
import scala.concurrent.duration._ | |
object StreamingChunksIO extends IOApp.Simple { | |
def mapCheck = Stream |
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
//> using lib "co.fs2::fs2-core:3.5.0" | |
//> using lib "org.typelevel::cats-effect:3.4.6" | |
import fs2.Stream | |
object StreamingChunks { | |
def mapCheck = Stream | |
.emits(0 until 100) | |
.chunkN(10) |
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
case class BlerfCache( | |
blerfs: Ref[IO, Map[Id, Blerf]], | |
private val getBlerfMap: IO[Map[Id, Blerf]], | |
) extends Logging { | |
def updateBlerfs: IO[Unit] = getBlerfMap.flatMap(b => blerfs.set(b)) | |
def refreshCache: IO[Unit] = | |
Stream | |
.repeatEval(logger.debug("refreshing blerf...") *> updateBlerfs) | |
.metered(5.minutes) |
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
//> using scala "2.13.10" | |
//> using lib "org.typelevel::cats-effect:3.4.8" | |
//> using lib "org.http4s::http4s-ember-client:0.23.18" | |
//> using lib "org.http4s::http4s-ember-server:0.23.18" | |
//> using lib "org.http4s::http4s-server:0.23.18" | |
//> using lib "org.http4s::http4s-dsl:0.23.18" | |
//> using lib "org.http4s::http4s-circe:0.23.18" | |
//> using lib "io.circe::circe-core:0.14.5" | |
//> using lib "io.circe::circe-generic:0.14.5" | |
//> using lib "org.scodec::scodec-bits:1.1.37" |
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
//> using lib "co.fs2::fs2-core:3.4.0" | |
//> using lib "org.typelevel::cats-effect:3.4.4" | |
/** Toy example with with metered stream. What happens if a stream element takes longer than metering? | |
*/ | |
import fs2.Stream | |
import cats.effect.IO | |
import cats.effect.IOApp | |
import scala.concurrent.duration._ | |
import cats.effect.kernel.Ref |
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
//> using lib "org.typelevel::cats-effect:3.4.8" | |
import cats.effect.{IO, IOApp} | |
import cats.effect.std.Dispatcher | |
import scala.concurrent.duration._ | |
object Example extends IOApp.Simple { | |
def run: IO[Unit] = | |
Dispatcher.parallel[IO](await = true).use { dispatcher => |
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 cats.effect.std.Dispatcher | |
import scala.concurrent.duration._ | |
import scala.concurrent.{Await, ExecutionContext, Future} | |
import cats.effect.unsafe.implicits.global | |
object StackTraceExample { | |
case class SomeError(message: String) extends Exception | |
val (dispatcher, dispatcherShutdown) = Dispatcher.parallel[IO].allocated.unsafeRunSync() |
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
//> using lib "org.typelevel::cats-effect:3.4.7" | |
//> using lib "org.http4s::http4s-core:0.23.18" | |
//> using lib "org.http4s::http4s-dsl:0.23.18" | |
//> using lib "org.http4s::http4s-ember-client:0.23.18" | |
//> using lib "org.http4s::http4s-client:0.23.18" | |
//> using lib "org.http4s::http4s-circe:0.23.18" | |
//> using lib "io.circe::circe-core:0.14.4" | |
//> using lib "io.circe::circe-literal:0.14.4" | |
import cats.effect.kernel.Resource |
NewerOlder