diff options
author | Matt Joiner <anacrolix@gmail.com> | 2019-11-01 12:23:59 +1100 |
---|---|---|
committer | Matt Joiner <anacrolix@gmail.com> | 2019-11-01 12:23:59 +1100 |
commit | 52e150e44234b631f8a9b2de11862434046b4992 (patch) | |
tree | b57bdf74630b62e2c2dfebe45569cc7da94838be /stmutil/context.go | |
parent | Optimize a bunch of stuff (diff) | |
download | stm-52e150e44234b631f8a9b2de11862434046b4992.tar.gz stm-52e150e44234b631f8a9b2de11862434046b4992.tar.xz |
Add stmutil containers and ContextDoneVar
Diffstat (limited to 'stmutil/context.go')
-rw-r--r-- | stmutil/context.go | 17 |
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 +} |