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

dave08

10/18/2017, 9:52 AM
I have an android SyncService (with SyncAdapter) and another IntentService that recieves a broadcast to do the same sync action that's build on coroutines. I would like to be able to run it from both places but if the sync is already running, it should push off the second sync until the first is finished. At first I used a Channel(), with
fun startSync() { runBlocking { syncStartChannel.send(Unit) } }
. Then I thought that might be overkill so I tried a Mutex
fun startSync() { runBlocking {  mux.lock(); try { syncStartChannel.send(Unit) } finally { mux.unlock() } } }
. It worked at a certain time, then for some reason the sync gets skipped altogether... Is there any better way?