Skip to content

Instantly share code, notes, and snippets.

@jonnyzzz
Created December 15, 2016 17:53
Show Gist options
  • Save jonnyzzz/05c0febc22720e77d13b9dd70b467047 to your computer and use it in GitHub Desktop.
Save jonnyzzz/05c0febc22720e77d13b9dd70b467047 to your computer and use it in GitHub Desktop.
Make sure state is accessed only by lock in Kotlin
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