https://kotlinlang.org logo
Title
r

Raphael Almeida

03/21/2020, 5:16 PM
Is there any way to throtle the messages to a channel? Adding delay to the messages given a param of the msg. Linke a priority queue or delayed queue? I though to just run a coroutine and then delay but it seems no good for a fan out scenario.
z

Zach Klippenstein (he/him) [MOD]

03/21/2020, 6:03 PM
Do you want to throttle the messages being sent to the channel, or being sent to consumers of the channel? If the latter, it sounds like you should be using Flow instead of exposing a channel directly.
r

Raphael Almeida

03/21/2020, 6:06 PM
Actually to a work pool. I'd like to add a delay for a htp calls to same host, but keeping calling for other as much as available.
@Zach Klippenstein (he/him) [MOD] Would you have exmples of it?
z

Zach Klippenstein (he/him) [MOD]

03/21/2020, 6:10 PM
Could you keep a map of host to semaphore, and use the semaphores to throttle per-host?
r

Raphael Almeida

03/21/2020, 6:15 PM
The apache client does it to ative max per host. But no add a delay after a call no. I was wordering to do it without a semaphore. In java you have thr DelayedQuee or Priority. The most close thing I found in kotlin was a time schedule.
z

Zach Klippenstein (he/him) [MOD]

03/21/2020, 7:46 PM
Just call
delay()
from your worker coroutines?