Created
August 5, 2018 19:31
-
-
Save mrmitew/6b6b70e231fa40dbf0e16bffc1590974 to your computer and use it in GitHub Desktop.
Set a click listener on a view, backed up by an actor that discards all clicks until the suspending action returns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set a click listener on a view and back it up by an actor that allows | |
* execution of a single action block at a time. Subsequent requests will be discarded until action returns. | |
*/ | |
fun View.setOnRendezvousClickListener(action: suspend (View) -> Unit) { | |
val eventActor = actor<View>(UI, capacity = 0) { | |
for (event in channel) action(event) | |
} | |
setOnClickListener { | |
eventActor.offer(it) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment