aboutsummaryrefslogtreecommitdiff
path: root/stmutil/context.go
diff options
context:
space:
mode:
authorMatt Joiner <anacrolix@gmail.com>2019-11-01 12:23:59 +1100
committerMatt Joiner <anacrolix@gmail.com>2019-11-01 12:23:59 +1100
commit52e150e44234b631f8a9b2de11862434046b4992 (patch)
treeb57bdf74630b62e2c2dfebe45569cc7da94838be /stmutil/context.go
parentOptimize a bunch of stuff (diff)
downloadstm-52e150e44234b631f8a9b2de11862434046b4992.tar.gz
stm-52e150e44234b631f8a9b2de11862434046b4992.tar.xz
Add stmutil containers and ContextDoneVar
Diffstat (limited to 'stmutil/context.go')
-rw-r--r--stmutil/context.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/stmutil/context.go b/stmutil/context.go
new file mode 100644
index 0000000..49f211c
--- /dev/null
+++ b/stmutil/context.go
@@ -0,0 +1,17 @@
+package stmutil
+
+import (
+ "context"
+
+ "github.com/lukechampine/stm"
+)
+
+func ContextDoneVar(ctx context.Context) (*stm.Var, func()) {
+ ctx, cancel := context.WithCancel(ctx)
+ _var := stm.NewVar(false)
+ go func() {
+ <-ctx.Done()
+ stm.AtomicSet(_var, true)
+ }()
+ return _var, cancel
+}