Created
October 7, 2018 18:53
-
-
Save danherrera/498d52a0da3d969366ad51019226d7be to your computer and use it in GitHub Desktop.
LiveData Event that only emits if it has not been consumed.
From Florina Muntenescu's KotlinConf 2018 presentation: https://youtu.be/Sy6ZdgqrQp0?t=1579
This file contains hidden or 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
open class Event<out T>(private val content: T) { | |
var consumed = false | |
private set | |
fun consume(): T? { | |
return if (consumed) { | |
null | |
} else { | |
consumed = true | |
content | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment