aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-07-04 23:27:12 +0900
committerOphestra <cat@gensokyo.uk>2026-07-04 23:27:12 +0900
commit5bf87561f52c29dd0159a9828f999a021508f85e (patch)
tree652f5e4b56df308d0227b47713fd1b9cef2a1c12 /internal/pkg
parentdde69dde61e57fa929596294f6b4e8f798f5598e (diff)
internal/pkg: move concurrent cure implementation
This is useful independent of cure and might replace the Collect hack. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg')
-rw-r--r--internal/pkg/pkg.go40
1 files changed, 23 insertions, 17 deletions
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go
index d3816f08..489e34f4 100644
--- a/internal/pkg/pkg.go
+++ b/internal/pkg/pkg.go
@@ -1922,6 +1922,28 @@ func (c *Cache) tryExtern(
return checksum, err
}
+// cureMany concurrently collects outcome of multiple [Artifact].
+func (c *Cache) cureMany(inputs []Artifact, r map[Artifact]cureRes) error {
+ var wg sync.WaitGroup
+ wg.Add(len(inputs))
+ res := make([]cureRes, len(inputs))
+ errs := make(DependencyCureError, 0, len(inputs))
+ var errsMu sync.Mutex
+ for i, d := range inputs {
+ pending := pendingArtifactDep{d, &res[i], &errs, &errsMu, &wg}
+ go pending.cure(c)
+ }
+ wg.Wait()
+
+ if len(errs) > 0 {
+ return &errs
+ }
+ for i, p := range res {
+ r[inputs[i]] = p
+ }
+ return nil
+}
+
// cure implements Cure without acquiring a read lock on abortMu. cure must not
// be entered during Abort.
func (c *Cache) cure(a Artifact, curesExempt bool) (
@@ -2182,25 +2204,9 @@ func (c *Cache) cure(a Artifact, curesExempt bool) (
case FloodArtifact:
inputs := a.Inputs()
f := FContext{t, make(map[Artifact]cureRes, len(inputs))}
-
- var wg sync.WaitGroup
- wg.Add(len(inputs))
- res := make([]cureRes, len(inputs))
- errs := make(DependencyCureError, 0, len(inputs))
- var errsMu sync.Mutex
- for i, d := range inputs {
- pending := pendingArtifactDep{d, &res[i], &errs, &errsMu, &wg}
- go pending.cure(c)
- }
- wg.Wait()
-
- if len(errs) > 0 {
- err = &errs
+ if err = c.cureMany(inputs, f.inputs); err != nil {
return
}
- for i, p := range res {
- f.inputs[inputs[i]] = p
- }
sh := sha512.New384()
err = c.encode(sh, a, f.inputs)