Scala, Concurrency, API, Project Loom, Java.
RateLimiter.withRateLimiter(2, 1.second) { rateLimiter => rateLimiter.runLimited { println(s"${LocalTime.now()} Running …") } // other logic } In a way, we are back to callbacks: the withRateLimiter method takes as a parameter a function, which should be called back with a running rate limiter.