dave08
06/24/2018, 3:34 PMChannel
like this:
val eventQueue = Channel<ApplicationInstallRequest>()
init {
initEventProcessor()
}
private fun initEventProcessor() = launch(Unconfined) {
for (request in eventQueue) {
processRequest(request)
}
}
override fun onEvent(event: ApplicationInstallRequest) {
eventQueue.sendBlocking(event)
}
from an Android SyncAdapter, but even when the sync is finished, the process keeps on going (some kind of leak...), does Unconfined have it's own thread or something?louiscad
06/24/2018, 3:55 PMdave08
06/24/2018, 3:57 PMlouiscad
06/24/2018, 4:05 PMRight, but then all processes should be stopped...?No, you misread/misunderstood my statement (which is inspired from Android docs)
I have enough Ram and no other apps runningThat's why your process doesn't get killed by Android
dave08
06/24/2018, 4:07 PMlouiscad
06/24/2018, 4:07 PMonDestroy()
is a good idea alsot would be fine if the Service was still alive... the problem is that the service is dead, and the process keeps running...That's totally normal.
dave08
06/24/2018, 4:08 PMonDestroy
?louiscad
06/24/2018, 4:09 PMSo I don't have to kill it on?onDestroy
dave08
06/24/2018, 4:09 PMlouiscad
06/24/2018, 4:10 PMonDestroy()
, especially if they involve I/O or other limited resources that may drain the battery or consume power/resources needlessly when you should have stopped the workdave08
06/24/2018, 4:14 PMonDestroy
, which was my problem in the first place 🤕 , so the download won't run... I think I'm doing something wrong with coroutines...suspend fun
instead of all the actors and launches... I started having these problems...louiscad
06/24/2018, 4:18 PMdave08
06/24/2018, 4:23 PMlouiscad
06/24/2018, 4:30 PMdave08
06/24/2018, 4:53 PMlouiscad
06/24/2018, 6:37 PMMutex
(from kotlinx.coroutines, which suspends instead of blocking), which you put in a top level val or in an object
, or an actor
. And not a big deal if sync continues after the service or sync adapter is stopped. If there's not internet, it will fail and stop by itself, and if the system really needs the resources, it will throttle or kill the processdave08
06/24/2018, 7:20 PMlouiscad
06/25/2018, 11:32 AMsendBlocking
doesn't suspend but blocks while the underlying send
is suspended (if offer
didn't work in the first place). You shall never use sendBlocking
from a coroutinedave08
06/25/2018, 11:34 AMService
...dekans
06/26/2018, 11:00 AMoffer
and it works perfectlylouiscad
06/26/2018, 12:41 PMoffer
has different behaviors following the type or capacity of the channel though, it's important to be sure it's right for the use case