diff options
author | lukechampine <luke.champine@gmail.com> | 2016-03-30 00:22:36 -0400 |
---|---|---|
committer | lukechampine <luke.champine@gmail.com> | 2016-03-30 00:22:36 -0400 |
commit | c3dd091ff2df4499a1d568719fbe59a2bde1bf87 (patch) | |
tree | 916258eb1faece37f9c5f6418571c70ebdb08e5f | |
parent | rename Check -> Assert (diff) | |
download | stm-c3dd091ff2df4499a1d568719fbe59a2bde1bf87.tar.gz stm-c3dd091ff2df4499a1d568719fbe59a2bde1bf87.tar.xz |
add some helper functions
-rw-r--r-- | stm.go | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -212,3 +212,27 @@ retry: } globalLock.Unlock() } + +// Get is a helper transaction that reads a value. +func Get(v *Var, recv *interface{}) func(*Tx) { + return func(tx *Tx) { + *recv = tx.Get(v) + } +} + +// Set is a helper transaction that writes a value. +func Set(v *Var, val interface{}) func(*Tx) { + return func(tx *Tx) { + tx.Set(v, val) + } +} + +// Compose is a helper function that composes multiple transactions into a +// single transaction. +func Compose(fns ...func(*Tx)) func(*Tx) { + return func(tx *Tx) { + for _, f := range fns { + f(tx) + } + } +} |