Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
interface Base{
fun foo()
}
class BI : Base{
override fun foo() {
}
}
class InMainThreadThing (val b : Base, val handler: Handler) : Base by b{
override fun foo() {
accept { b.foo() }
}
}
class Test{
val x:InMainThreadThing = InMainThreadThing(BI(), Handler());
}
fun InMainThreadThing.accept(f: () -> Unit ) {
if (Looper.getMainLooper().thread == Thread.currentThread()) {
f.invoke()
} else {
this.handler.post(f)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment