Scoop API

scoop:scoop.ui:0.1.0

src/lifecycle/errors.scoop

Selected production source · src/lifecycle/errors.scoop

1package scoop.ui
3import scoop.platform.concurrent.ThreadId
4import scoop.platform.concurrent.currentThreadId
6internal fun checkUiThread(thread: ThreadId) {
7 if (currentThreadId() != thread)
8 throw IllegalStateException(Some("UI requires its owner thread"))
9}
11internal fun requireUi(condition: Boolean, message: String) {
12 if (!condition)
13 throw IllegalArgumentException(Some(message))
16internal 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 previous
29internal fun throwUi(failure: Throwable?) {
30 when (failure) {
31 case Some(val error) -> throw error
32 case None -> {}
33 }