create templates concurrently

This commit is contained in:
onyx-and-iris 2025-03-12 13:30:17 +00:00
parent c2b7dfcb18
commit fcb23a3c01
2 changed files with 19 additions and 4 deletions

View File

@ -44,7 +44,7 @@ tasks:
generate:
desc: Generate the gitignore.io templates
cmds:
- go generate .
- go generate ./...
build-windows:
desc: Build the gignore project for Windows

View File

@ -20,10 +20,25 @@ func main() {
log.Fatal(err)
}
errChan := make(chan error)
doneChan := make(chan struct{})
for _, template := range templates {
err := createTemplate(template)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create template %s: %v\n", template.Name, err)
go func() {
err := createTemplate(template)
if err != nil {
errChan <- fmt.Errorf("Failed to create template %s: %v", template.Name, err)
return
}
doneChan <- struct{}{}
}()
}
for range templates {
select {
case err := <-errChan:
log.Error(err)
case <-doneChan:
}
}
}