Daniel Zhang
09/28/2022, 11:40 PMrunBlocking {
withTimeoutOrNull(1000) {
inputs.asSequence().repeat().asFlow()
.rateLimiter(rateLimiter)
.map { executeInput(it) }
.toList()
}
}
val rateLimiter = RateLimiter.of(
properties.name,
RateLimiterConfig
.custom()
.limitForPeriod(properties.rateLimiter.limitForPeriod)
.limitRefreshPeriod(properties.rateLimiter.limitRefreshPeriod)
.timeoutDuration(properties.rateLimiter.timeoutDuration)
.build()
)
/**
* @see <a href="<https://stackoverflow.com/questions/48007311/how-do-i-infinitely-repeat-a-sequence-in-kotlin>">Infinite Sequence</a>
*/
private fun <T> Sequence<T>.repeat() = sequence { while (true) yieldAll(this@repeat) }
Here I’m attempting to turn a list of inputs into an infinite sequence that I can then throttle with a RateLimiter + time out after a certain duration, but neither seem to be working.Daniel Zhang
09/28/2022, 11:46 PM