blob: 1adcfd0d2b8f42016f2e862681b69d019e8275ff (
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[R any](fn Operation[R], tx *Tx) (result R, gotRetry bool) {
defer func() {
if r := recover(); r == retry {
gotRetry = true
} else if r != nil {
panic(r)
}
}()
result = fn(tx)
return
}
|