aboutsummaryrefslogtreecommitdiff
path: root/stmutil/context.go
diff options
context:
space:
mode:
authorChris Wendt <chrismwendt@gmail.com>2022-06-08 02:28:37 -0600
committerChris Wendt <chrismwendt@gmail.com>2022-06-08 03:02:44 -0600
commit30943ded71e123886291ad393e55bfb6aa837df3 (patch)
treeca7cc2520959386d6c57d9204f284be217bb0b72 /stmutil/context.go
parentuse generic atomic (diff)
downloadstm-30943ded71e123886291ad393e55bfb6aa837df3.tar.gz
stm-30943ded71e123886291ad393e55bfb6aa837df3.tar.xz
BIG change: generic Var[T], txVar, etc.
Diffstat (limited to 'stmutil/context.go')
-rw-r--r--stmutil/context.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/stmutil/context.go b/stmutil/context.go
index 8a4d58d..9d23e12 100644
--- a/stmutil/context.go
+++ b/stmutil/context.go
@@ -9,12 +9,12 @@ import (
var (
mu sync.Mutex
- ctxVars = map[context.Context]*stm.Var{}
+ ctxVars = map[context.Context]*stm.Var[bool]{}
)
// Returns an STM var that contains a bool equal to `ctx.Err != nil`, and a cancel function to be
// called when the user is no longer interested in the var.
-func ContextDoneVar(ctx context.Context) (*stm.Var, func()) {
+func ContextDoneVar(ctx context.Context) (*stm.Var[bool], func()) {
mu.Lock()
defer mu.Unlock()
if v, ok := ctxVars[ctx]; ok {
@@ -26,7 +26,7 @@ func ContextDoneVar(ctx context.Context) (*stm.Var, func()) {
v := stm.NewBuiltinEqVar(true)
return v, func() {}
}
- v := stm.NewVar(false)
+ v := stm.NewVar[bool](false)
go func() {
<-ctx.Done()
stm.AtomicSet(v, true)