aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlukechampine <luke.champine@gmail.com>2016-03-30 00:22:36 -0400
committerlukechampine <luke.champine@gmail.com>2016-03-30 00:22:36 -0400
commitc3dd091ff2df4499a1d568719fbe59a2bde1bf87 (patch)
tree916258eb1faece37f9c5f6418571c70ebdb08e5f
parentrename Check -> Assert (diff)
downloadstm-c3dd091ff2df4499a1d568719fbe59a2bde1bf87.tar.gz
stm-c3dd091ff2df4499a1d568719fbe59a2bde1bf87.tar.xz
add some helper functions
-rw-r--r--stm.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/stm.go b/stm.go
index 973734c..2960ac3 100644
--- a/stm.go
+++ b/stm.go
@@ -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)
+ }
+ }
+}