Commit ec17d58

Jason Cox  ·  2025-03-23 23:13:06 -0400 EDT
parent 81f5f00
Ensure all revisions get built (#5)

The first revision builds synchronously, and then the others build in
parallel. Use a wait group to ensure that the program doesn't exit
before the other builds finish.
1 files changed,  +9, -7
+9, -7
......@@ -626,7 +626,6 @@ func (c *Config) writeRepo() *BranchOutput {
626626
627627 refInfoMap := map[string]*RefInfo{}
628628 mainOutput := &BranchOutput{}
629- claimed := false
630629 for _, revData := range revs {
631630 refInfoMap[revData.Name()] = &RefInfo{
632631 ID: revData.ID(),
......@@ -665,7 +664,8 @@ func (c *Config) writeRepo() *BranchOutput {
665664 return urlI > urlJ
666665 })
667666
668- for _, revData := range revs {
667+ var wg sync.WaitGroup
668+ for i, revData := range revs {
669669 c.Logger.Info("writing revision", "revision", revData.Name())
670670 data := &PageData{
671671 Repo: c,
......@@ -673,16 +673,18 @@ func (c *Config) writeRepo() *BranchOutput {
673673 SiteURLs: c.getURLs(),
674674 }
675675
676- if claimed {
676+ if i == 0 {
677+ branchOutput := c.writeRevision(repo, data, refInfoList)
678+ mainOutput = branchOutput
679+ } else {
680+ wg.Add(1)
677681 go func() {
682+ defer wg.Done()
678683 c.writeRevision(repo, data, refInfoList)
679684 }()
680- } else {
681- branchOutput := c.writeRevision(repo, data, refInfoList)
682- mainOutput = branchOutput
683- claimed = true
684685 }
685686 }
687+ wg.Wait()
686688
687689 // use the first revision in our list to generate
688690 // the root summary, logs, and tree the user can click