scoop:scoop.ui:0.1.0
src/lifecycle/errors.scoop
Selected production source · src/lifecycle/errors.scoop
1
package scoop.ui3
import scoop.platform.concurrent.ThreadId4
import scoop.platform.concurrent.currentThreadId6
internal fun checkUiThread(thread: ThreadId) {7
if (currentThreadId() != thread)8
throw IllegalStateException(Some("UI requires its owner thread"))9
}11
internal fun requireUi(condition: Boolean, message: String) {12
if (!condition)13
throw IllegalArgumentException(Some(message))14
}16
internal fun cleanupUi(previous: Throwable?, action: () -> Unit): Throwable? {17
try {18
action()19
}20
catch (error: Throwable) {21
return when (previous) {22
case Some(val primary) -> Some(ResourceUseException(primary, error))23
case None -> Some(error)24
}25
}26
return previous27
}29
internal fun throwUi(failure: Throwable?) {30
when (failure) {31
case Some(val error) -> throw error32
case None -> {}33
}34
}