def deref(self): """Returns either the in-transaction-value of this ref if there is an active transaction, or returns the last committed value of ref""" transaction = LockingTransaction.get() if transaction: return transaction.getRef(self) return self._currentVal()
def touch(self): """Ensures that this ref cannot be given a new in-transaction-value by any other transactions for the duration of this transaction""" LockingTransaction.ensureGet().doEnsure(self)
def commute(self, fn, args): """Commutes the value of this ref, allowing for it to be updated by other transactions before the commuting function is called""" return LockingTransaction.ensureGet().doCommute(self, fn, args)
def alter(self, fn, args): "Alters the value of this ref, and returns the new state" current = LockingTransaction.ensureGet().getRef(self) return self.refSet(fn(*RT.cons(current, args)))
def refSet(self, state): """Sets the value of this ref to the desired state, regardless of the current value. Returns the newly set state""" return LockingTransaction.ensureGet().doSet(self, state)