From c3dd091ff2df4499a1d568719fbe59a2bde1bf87 Mon Sep 17 00:00:00 2001 From: lukechampine Date: Wed, 30 Mar 2016 00:22:36 -0400 Subject: add some helper functions --- stm.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'stm.go') 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) + } + } +} -- cgit v1.2.3