efemoney
05/20/2024, 11:11 AMfinally
block that something failed?
val token = acquireLock(state.entityId) ?: return finish()
var failed = false
try {
doLockBasedOperation()
} catch (e: Exception) {
failed = true
throw e
} finally {
withContext(NonCancellable) {
releaseLock(state.entityId, token, failed)
}
}
Will finally
still run even though I rethrew in catch block? 🤔
Or am I supposed to duplicate the lock release into the catch
block?Sam
05/20/2024, 11:34 AMefemoney
05/20/2024, 11:35 AMDaniel Pitts
05/20/2024, 2:39 PMDaniel Pitts
05/20/2024, 2:40 PMval token = acquireLock(state.entityId) ?: return finish()
var success = false
try {
doLockBasedOperation()
success = true
} finally {
withContext(NonCancellable) {
releaseLock(state.entityId, token, !success)
}
}
efemoney
05/20/2024, 4:21 PM