aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorKir Kolyshkin <kolyshkin@gmail.com>2024-09-04 18:38:05 -0700
committerGopher Robot <gobot@golang.org>2024-09-06 13:28:33 +0000
commita77b93c0b2e2c50d1b0b9d181a4ee4eaf04f8821 (patch)
tree9c6f937489888f8140176c2b133f3ac063c30527 /src/cmd
parenta1c3e24b5466ede5dd2d817cadc6d91d1ae56f18 (diff)
downloadgo-a77b93c0b2e2c50d1b0b9d181a4ee4eaf04f8821.tar.xz
cmd/internal/script: use sync.OnceValue
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>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/internal/script/conds.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/cmd/internal/script/conds.go b/src/cmd/internal/script/conds.go
index 25dd6e17ea..30759d2a58 100644
--- a/src/cmd/internal/script/conds.go
+++ b/src/cmd/internal/script/conds.go
@@ -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