efemoney
05/10/2024, 3:23 PMfinally
block … foot marksmanship or not? 🤔
(Or put another way, is it a bad idea to run a suspend function in the finally block? Use case is I don’t want to catch errors from suspendFunA()
but I need to cleanup resources used & reset a lock within suspendFunB()
)
try {
~ suspendFunA()
} finally {
~ suspendFunB()
}
Sam
05/10/2024, 3:26 PMsuspendFunB()
will just fail again as soon as it tries to suspend. To fix it:
try {
suspendFunA()
} finally {
withContext(NonCancellable) {
suspendFunB()
}
}
Sam
05/10/2024, 3:26 PMefemoney
05/10/2024, 3:26 PMYoussef Shoaib [MOD]
05/10/2024, 4:49 PMResource
datatype that does exactly this (with NonCancellable
) so I would say yes this is the way to go. You might wanna use their ResourceScope
abstraction if you're doing this a lot