diff options
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 +} |