Created
November 7, 2019 00:51
-
-
Save timmc/de68a914f0f546b608d60f5fa9f7a069 to your computer and use it in GitHub Desktop.
A synchronized setter with side-effects in Kotlin (probably a bad idea!)
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
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