Skip to content

Instantly share code, notes, and snippets.

@timmc
Created November 7, 2019 00:51
Show Gist options
  • Save timmc/de68a914f0f546b608d60f5fa9f7a069 to your computer and use it in GitHub Desktop.
Save timmc/de68a914f0f546b608d60f5fa9f7a069 to your computer and use it in GitHub Desktop.
A synchronized setter with side-effects in Kotlin (probably a bad idea!)
private var writeLock = Object()
/**
* The canonical version of config that is on disk, barring any sneaky
* writes; setting this property causes a disk write.
*/
var config: Config = repo.config.readJson()
set(newConfig) {
synchronized(writeLock) {
repo.config.writeJson(newConfig)
field = newConfig
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment