Skip to content

Commit

Permalink
examples
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Jan 3, 2025
1 parent 67be6ee commit 8bd7ebd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// {cat=Resilience; effects=Direct; backend=HttpClient}: Rate limit sending requests using Ox

//> using dep com.softwaremill.sttp.client4::ox:4.0.0-M22

package sttp.client4.examples.resilience

import ox.Ox
import ox.OxApp
import sttp.client4.*

import scala.concurrent.duration.*
import ox.resilience.RateLimiter
import java.time.Instant

object RateLimitOx extends OxApp.Simple:
override def run(using Ox): Unit =
val backend = DefaultSyncBackend()

val rateLimiter = RateLimiter.fixedWindow(1, 3.seconds)
for (_ <- 1 to 5)
rateLimiter.runBlocking {
println(s"${Instant.now()} Sending request ...")
basicRequest.get(uri"https://httpbin.org/status/500").send(backend)
}

0 comments on commit 8bd7ebd

Please sign in to comment.