]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/script: use sync.OnceValue
authorKir Kolyshkin <kolyshkin@gmail.com>
Thu, 5 Sep 2024 01:38:05 +0000 (18:38 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 6 Sep 2024 13:28:33 +0000 (13:28 +0000)
Change-Id: I384a7391a26f24402c055aec98b37927305e2a39
Reviewed-on: https://go-review.googlesource.com/c/go/+/611042
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/cmd/internal/script/conds.go

index 25dd6e17ea3bde4f90646e1c839d6d5b94198722..30759d2a58d48e15ace2806f1477c1a046c71ace 100644 (file)
@@ -123,13 +123,13 @@ func (b *boolCond) Eval(s *State, suffix string) (bool, error) {
 // The eval function is not passed a *State because the condition is cached
 // across all execution states and must not vary by state.
 func OnceCondition(summary string, eval func() (bool, error)) Cond {
-       return &onceCond{eval: eval, usage: CondUsage{Summary: summary}}
+       return &onceCond{
+               eval:  sync.OnceValues(eval),
+               usage: CondUsage{Summary: summary},
+       }
 }
 
 type onceCond struct {
-       once  sync.Once
-       v     bool
-       err   error
        eval  func() (bool, error)
        usage CondUsage
 }
@@ -140,8 +140,7 @@ func (l *onceCond) Eval(s *State, suffix string) (bool, error) {
        if suffix != "" {
                return false, ErrUsage
        }
-       l.once.Do(func() { l.v, l.err = l.eval() })
-       return l.v, l.err
+       return l.eval()
 }
 
 // CachedCondition is like Condition but only calls eval the first time the