Billy Newman
10/24/2023, 7:28 PMprivate var pushJob: Job? = null
fun onEvent(event: Event) {
// Called on Main thread
lifecycleScope.launch {
eventRepository.save() // Executes on IO thread
pushJob?.join()
pushJob = push(location)
}
}
private suspend fun push() = coroutineScope {
launch {
Log.v("Test", "start push")
...
locationRepository.pushLocations() // Executes on IO thread
...
Log.v("Test", "end push")
}
}
Attempt a single push function executing at any given time. However I am not seeing start/stop pairs in the logs. Issue with the join and assignment not being synchronized?ephemient
10/24/2023, 7:39 PMcoroutineScope { launch { ... } }
is basically equivalent to ...
, the job is always complete by the time the suspend fun
returnsBilly Newman
10/24/2023, 9:28 PMfun onEvent(event: Event) {
// Called on Main thread
lifecycleScope.launch {
eventRepository.save() // Executes on IO thread
pushJob?.join()
pushJob = launch {
Log.v("Test", "start push")
...
locationRepository.pushLocations() // Executes on IO thread
...
Log.v("Test", "end push")
}
}
}
ephemient
10/24/2023, 9:29 PMMutex
?limitedParallelism
dispatcher, if what you're running is a blocking operationBilly Newman
10/24/2023, 9:35 PMfun onEvent(event: Event) {
// Called on Main thread
lifecycleScope.launch {
eventRepository.save() // Executes on IO thread
mutex.withLock {
Log.v("Test", "start push")
...
locationRepository.pushLocations() // Executes on IO thread
...
Log.v("Test", "end push")
}
}
}