Hi guys, I think my question is very simple, but f...
# flow
a
Hi guys, I think my question is very simple, but for some reason I can't find the answer. I'm guessing I have an infinite SharedFlow, which 100ms makes a difference. How can I get all the values once per minute? I understand that you can simply use .take() or .toList(), but in the first case I need to specify the exact value that I want to get, and in the second I will get a constantly changing collection
m
debounce(1.minutes).collect {} // or toList()
?
1
a
Hmm, I think it looks good. Thank you
s
Does it really fit your usecase? If values are being emitted more frequently than 1 per minute, you will never ever collect anything
a
Yes, it didn't quite fit. I solved the problem through toList and clearing the collection via mutex
m
Sorry @Andrey, I think I misunderstood your question. I think what you're looking for is something like this: https://blog.shreyaspatil.dev/collecting-items-from-the-flow-in-chunks which is probably similar to the approach you took to solve this problem(it uses a mutex under the hood and clears the list after each interval)
👍 1
a
Yes, I wrote almost the same thing. And it works. I'm sure there are better solutions