Skip to content

Instantly share code, notes, and snippets.

@Chickinnick
Created October 24, 2018 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chickinnick/439d08378baa909c199a648dce9b986a to your computer and use it in GitHub Desktop.
Save Chickinnick/439d08378baa909c199a648dce9b986a to your computer and use it in GitHub Desktop.
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