component output = false hint = "I manage synchronized access to some sort of internal data store." { /** * I read some data from the underlying synchronized data collection. */ public any function getSomeData() { lock attributeCollection = synchronizedRead() { // ... READ some data within the READ-ONLY lock. } } /** * I change some data in the underlying synchronized data collection. */ public void function mutateSomeData() { lock attributeCollection = synchronizedWrite() { // ... MUTATE some data within the EXCLUSIVE lock. } } // --- // PRIVATE METHODS. // --- /** * I build the attributes for a read-only lock with the given timeout. */ private struct function synchronizedRead( numeric timeoutInSeconds = 1 ) { return { name: "ManagerLockForGreatGood", type: "readonly", timeout: timeoutInSeconds }; } /** * I build the attributes for an exclusive lock with the given timeout. */ private struct function synchronizedWrite( numeric timeoutInSeconds = 1 ) { // The only difference between the READ and the WRITE lock is the [type]. As such, // we're going to use the read lock to define the base attributes and then simply // override the type. This way, the lock name is only defined in one place. return synchronizedRead( timeoutInSeconds ).append({ type: "exclusive" }); } }