<https://kt.academy/article/slowing-down-coroutine...
# feed
j
j
Thanks for the article!
Option2: we launch a delay in parallel with the body. Although this seems elegant, it is a bit heavy.
Could you explain how is this “heavy”?
r
I would actually prefer option 2, instead of option 3 (where the production code gets 'polluted' with test code, and the behaviour is different between test and normal execution)
same 1
j
Me too, that’s why I want to understand why option 2 is not chosen 🙂
j
hi Johann! Coroutines themselves are fairly lightweight, but they're not free. Option2 is probably fine in most scenarios. If you're squeezing your infrastructure for small performance optimisations, then option3 is less heavy since you have one fewer job being created, but then you should probably also stick to Long instead of TimedValue to reduce further allocations I'll benchmark the two options at some point to get some numbers under load
j
Yeah I think benchmarks are required here, but you’re right: delay creates a new job, however I don’t really know its implementation, it might be really lightweight?
k
Thanks for sharing, I was supposed to do that myself 😄 Great article, by the way.
❤️ 1