Created
December 15, 2016 17:53
-
-
Save jonnyzzz/05c0febc22720e77d13b9dd70b467047 to your computer and use it in GitHub Desktop.
Make sure state is accessed only by lock in Kotlin
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
class GuardedByLock<out T>( | |
val lock : Lock, | |
val state : T | |
) { | |
inline fun <Y> withLock(action : T.() -> Y) = lock.withLock { state.action() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment