Skip to content

Instantly share code, notes, and snippets.

@i-am-the-slime
Created April 21, 2026 14:49
Show Gist options
  • Select an option

  • Save i-am-the-slime/4b7121226cff55ce06d2504be82e02d3 to your computer and use it in GitHub Desktop.

Select an option

Save i-am-the-slime/4b7121226cff55ce06d2504be82e02d3 to your computer and use it in GitHub Desktop.
Scala DV Client PoC — evaluation, typed get, exposure logging (Scala 2.13)
//> using scala 2.13
//> using jar "dv_2.13.jar"
//> using dep "org.typelevel::cats-core:2.12.0"
//> using dep "org.typelevel::cats-effect:3.5.4"
//> using dep "com.lihaoyi::ujson:4.0.0"
//> using dep "com.thesamet.scalapb::scalapb-runtime:1.0.0-alpha.3"
import cats.effect.{IO, IOApp, Resource}
import cats.syntax.all._
import com.doordash.dv.DVClient
import com.doordash.dv.entity._
import com.doordash.dv.exposure._
import com.doordash.dv.listener.NoOpListener
import scala.concurrent.duration._
object Test213 extends IOApp.Simple {
val emitter: Resource[IO, ExposureEmitter[IO]] =
Resource.pure(new ExposureEmitter[IO] {
def emit(events: Vector[ExposureEvent]): IO[Unit] =
IO.println(s" [exposure] ${events.size} events: ${events.map(e => s"${e.experimentName.value}=${e.variantName.value}").mkString(", ")}")
})
val client: Resource[IO, DVClient[IO]] =
DVClient.withExposureLogging[IO](
configDir = ConfigDir("configs"),
reloadInterval = 30.seconds,
emitter = emitter
)
def run: IO[Unit] =
client.use { dv =>
val props = Properties.empty
.setString(PropertyKey("country"), "US")
.setRandomizationKey(RandomizationKey("user-12345"))
for {
_ <- IO.println("=== Scala 2.13 Test ===")
e1 <- dv.evaluate(DVName("dv_1"), props)
_ <- IO.println(s" dv_1: variant=${e1.variant.name.value} inRollout=${e1.inRollout}")
e2 <- dv.evaluate(DVName("dv_2"), props)
_ <- IO.println(s" dv_2: variant=${e2.variant.name.value}")
v <- dv.get[String](DVName("dv_3"), props, fallback = "default")
_ <- IO.println(s" dv_3: get[String]=$v")
r <- dv.evaluateSet(DVName("dv_1"), props)
_ <- IO.println(s" evaluateSet: ${r.evaluationSets.size} sets")
m <- dv.get[Boolean](DVName("missing"), props, fallback = false)
_ <- IO.println(s" missing: fallback=$m")
_ <- IO.println(" waiting for exposure flush...")
_ <- IO.sleep(6.seconds)
_ <- IO.println("=== Scala 2.13 PASSED ===")
} yield ()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment