aboutsummaryrefslogtreecommitdiff
path: root/retry.go
blob: 1997b18794664fcf95a62d0a4b02b9385a7235c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package stm

import (
	"runtime/pprof"
)

var retries = pprof.NewProfile("stmRetries")

// retry is a sentinel value. When thrown via panic, it indicates that a
// transaction should be retried.
var retry = &struct{}{}

// catchRetry returns true if fn calls tx.Retry.
func catchRetry(fn Operation, tx *Tx) (result interface{}, gotRetry bool) {
	defer func() {
		if r := recover(); r == retry {
			gotRetry = true
		} else if r != nil {
			panic(r)
		}
	}()
	result = fn(tx)
	return
}