I need to add chunking to some code that I was hop...
# multiplatform
t
I need to add chunking to some code that I was hoping to push down into commonMain. I have a web socket that blasts messages like a fire hose and I need to batch them by time or size. We have this logic implemented in Android already using some code that seems to be used widespread from Pin-Sho Feng. I believe that I'm not able to use that because timer is defined in kotlinx-coroutines-core-jvm. The compiler can't find it when I move the code to commonMain. Can somebody recommend a solution that would allow me to have my repository contain the web socket so that it can cache the messages in a local database? I'd like to have this repo used by iOS too.
This is the page that has the logic for the chunking we currently use. https://dev.to/psfeng/a-story-of-building-a-custom-flow-operator-buffertimeout-4d95
e
the issue I linked in your other thread has a related PR with discussion about implementation. what you choose will depend on what you actually need - there's lots of possible variations - but it's all straightforward with basic Kotlin coroutines and flow primitives
t
Thank you for the example. I had read through the links you sent and all the example code that I saw had dependencies on internal objects. I'm still learning so it was difficult to piece together a proper solution.