Andrew Gazelka
04/26/2019, 10:44 PMResource is
suspend fun take(priority: Int = 0, immediate: Boolean = false)
where a task with a lower priority will be scheduled first and higher later. The immediate argument will determine whether the currently executing process should be interrupted if take(...) has a lower priority than the currently executing task. A resource is given back with Resource#giveBack().
Any recommendations on how I could do this idiomatically?Dominaezzz
04/26/2019, 11:42 PMtake again? Does it just "pause" until the new coroutine is done?Andrew Gazelka
04/27/2019, 2:17 AMAndrew Gazelka
04/27/2019, 2:17 AMAndrew Gazelka
04/27/2019, 2:17 AMsuspend fun take(priority: Int = 0)Andrew Gazelka
04/27/2019, 2:18 AMwhile(true){
resource.take(9999)
// do things
resource.giveBack()
delay(1_000)
}Dominaezzz
04/27/2019, 9:47 AMPriorityMutex that'll be similar to the Mutex class. https://github.com/Kotlin/kotlinx.coroutines/blob/69c26dfbcefc24c66aadc586f9b5129894516bee/kotlinx-coroutines-core/common/src/sync/Mutex.kt but do some insertion sort.