https://kotlinlang.org logo
#coroutines
Title
# coroutines
k

Krishna Chinya

02/08/2023, 6:14 AM
Hello, I’m queuing network requests when device is offline in db and service picks it up and runs when device comes online. I was using rx java before, I moved whole thing to coroutines now and facing some issues which is blocking other network call until all my queued requests are complete. say, If I have 1000 requests queued and when I run it on dispatcher.io using limitedParallelism(5) it blocks other network calls that happens from app. Can someone please help . You can find the code snippet below.
Copy code
withContext(dispatchers.network.limitedParallelism(5)) {
            async { //build queuedrequest list }
            queuedRequests.awaitAll() 
            // then I process the request.
}
Android Service calls the above code snippet
Copy code
scope = CoroutineScope(<http://dispatchers.io|dispatchers.io> + SupervisorJob())

// Then
scope.launch { 
// calling the above code in repository  
}.launchIn(scope)
5 Views