What is the proper way to use Flow to run tasks fo...
# getting-started
d
What is the proper way to use Flow to run tasks for a given amount of time while also utilizing rate limiting? I have the following:
Copy code
runBlocking {
    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.
Going off the example from the Resilience4J docs here: https://resilience4j.readme.io/docs/getting-started-4#usage---flow