diff options
author | Matt Joiner <anacrolix@gmail.com> | 2019-11-02 21:42:51 +1100 |
---|---|---|
committer | Matt Joiner <anacrolix@gmail.com> | 2019-11-02 21:42:51 +1100 |
commit | 37d974cae9a0bc06ccdf26b0ff16f14ded1eac02 (patch) | |
tree | bf6edad46d143271f90fa1dc18bda81e869d4a28 | |
parent | Add stmutil containers and ContextDoneVar (diff) | |
download | stm-37d974cae9a0bc06ccdf26b0ff16f14ded1eac02.tar.gz stm-37d974cae9a0bc06ccdf26b0ff16f14ded1eac02.tar.xz |
stmutil.ContextDoneVar: Return true Var if the context is already done
This prevents needless races, such as in some of the rate limiting tests.
-rw-r--r-- | stmutil/context.go | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/stmutil/context.go b/stmutil/context.go index 49f211c..75e3f8a 100644 --- a/stmutil/context.go +++ b/stmutil/context.go @@ -7,6 +7,9 @@ import ( ) func ContextDoneVar(ctx context.Context) (*stm.Var, func()) { + if ctx.Err() != nil { + return stm.NewVar(true), func() {} + } ctx, cancel := context.WithCancel(ctx) _var := stm.NewVar(false) go func() { |