Hi. I'm looking for some project guidance. I'm new to Kotlin and Multiplatform and I need to write a Multiplatform SDK to support iOS and Android to interact with a REST based service (to make it easier for the customer to use basically). The SDK will be used by iOS and Android engineers that will then build all the UI and interactions from the SDK to their app. My piece (the SDK) has no visual aspect to it and boils down to making REST based calls and has a long polling call that will run the entire time the app is in use and when its not (keep going in the background). It will run a long polling for 2 minutes (if no response) then get disconnected and then re-connect. Also, it will reconnect if any data is returned. I'm using Ktor Client to make the calls and this is part working great. However, I have some questions and unfortunately couldn't find a lot of answers searching the internet.
1. To keep the long polling going through the life of the app it seems like running that in GlobalScope might be the only option but that looks like you have to be very careful not to leak memory, etc. While the long polling is going on they can still make requests to the SDK to fetch other endpoint's data. Is there another way that keeps this the long polling running even if the app isn't front and center? Options?
2. Passing data back from the SDK to the iOS or Android app. It looks like Flow, or State/Shared Flow is the usual way to do this. I want to pass back any data, status messages, etc. It looks like handing back a DTO of say a "Customer" object would be a good option as well. Otherwise, just passing simple strings would work for the other things. I found this article (
https://johnoreilly.dev/posts/realm-kotlinmultiplatform/) and it kind of looks like what I'd want but without the DB aspect (I don't need to long or short term persist data).
Thanks.