aboutsummaryrefslogtreecommitdiff
path: root/retry.go
diff options
context:
space:
mode:
authorMatt Joiner <anacrolix@gmail.com>2019-10-23 15:38:09 +1100
committerMatt Joiner <anacrolix@gmail.com>2019-10-23 15:38:09 +1100
commit7655ef3f131d1dfd33e1d0252df1aaaf04e31dc0 (patch)
treef626289c01711474d20b7f11dffcbdb8072f8b7a /retry.go
parentPut benchmarks in their own file (diff)
downloadstm-7655ef3f131d1dfd33e1d0252df1aaaf04e31dc0.tar.gz
stm-7655ef3f131d1dfd33e1d0252df1aaaf04e31dc0.tar.xz
Break up the stm.go file
Diffstat (limited to 'retry.go')
-rw-r--r--retry.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/retry.go b/retry.go
new file mode 100644
index 0000000..7800ae9
--- /dev/null
+++ b/retry.go
@@ -0,0 +1,18 @@
+package stm
+
+// Retry is a sentinel value. When thrown via panic, it indicates that a
+// transaction should be retried.
+const Retry = "retry"
+
+// catchRetry returns true if fn calls tx.Retry.
+func catchRetry(fn func(*Tx), tx *Tx) (retry bool) {
+ defer func() {
+ if r := recover(); r == Retry {
+ retry = true
+ } else if r != nil {
+ panic(r)
+ }
+ }()
+ fn(tx)
+ return
+}