https://kotlinlang.org logo
Title
e

elizarov

10/18/2017, 1:06 PM
@dave08 I’m somewhat lost at what problem you are trying to solve and what is the solution your are trying to apply. I don’t see how sending over channel inside a mutex should do anything. Can you post somewhere (like a gist) a larger example (a unit test, maybe?) that demonstrates what you are trying to do and what does not work?
u

uli

10/18/2017, 2:05 PM
I think @dave08 means to use the mutex approach as an alternative serialisation approach, instead of having a channel
d

dave08

10/18/2017, 2:06 PM
Right!
but both have their problems...
u

uli

10/18/2017, 2:19 PM
What's the issue with the channel approach? Sounds just right to me
d

dave08

10/18/2017, 2:21 PM
It was running well on the IntentService, but the SyncAdapter just terminated right away.. I tried join() but that stalled the whole app
val syncRequestChannel = Channel<SyncRequest>(Channel.CONFLATED)
val syncStarterJob by lazy {
		launchSyncStarter(syncRequestChannel)
	}
    fun launchSyncStarter(syncRequestChannel: ReceiveChannel<SyncRequest>) = launch(CommonPool) {
        syncRequestChannel.consumeEach { with(it) {
                // Sync instructions
        } }
    }

    override fun onSyncStart(context: Context, currSyncResult: SyncResult) {
        runBlocking { syncRequestChannel.send(Unit) }
}
@uli
u

uli

10/18/2017, 3:51 PM
which class is that? which onSyncStart are you overriding?
d

dave08

10/18/2017, 4:06 PM
But that's the first way I tried..
u

uli

10/18/2017, 4:07 PM
right, what is the base class of SyncAction?
Or is it just a
SyncHandler
?
d

dave08

10/18/2017, 4:09 PM
It's just a regular class not an android component..
u

uli

10/18/2017, 4:21 PM
I was wondering because of the override, But now I got it. found the
SyncHandler
interface