Make async

This commit is contained in:
2024-09-12 09:11:37 +02:00
parent 5cafdbf239
commit 63d9121e56
2 changed files with 21 additions and 12 deletions

31
main.go
View File

@@ -7,6 +7,7 @@ import (
"log"
"os"
"strings"
"sync"
"text/template"
"github.com/PuerkitoBio/goquery"
@@ -58,20 +59,26 @@ func main() {
return
}
wg := sync.WaitGroup{}
for _, file := range files {
class, err := ParseFile(file)
if err != nil {
Error.Printf("Error parsing file: %v", err)
continue
}
wg.Add(1)
go func(file string) {
defer wg.Done()
class, err := ParseFile(file)
if err != nil {
Error.Printf("Error parsing file: %v", err)
return
}
outfile, err := class.GetOutFile()
if err != nil {
Error.Printf("Error creating output file: %v", err)
return
}
ltemplate.Execute(outfile, class)
outfile, err := class.GetOutFile()
if err != nil {
Error.Printf("Error creating output file: %v", err)
return
}
ltemplate.Execute(outfile, class)
}(file)
}
wg.Wait()
}
func ParseFile(filename string) (*Class, error) {
@@ -156,7 +163,7 @@ func ParseFile(filename string) (*Class, error) {
res.Methods = append(res.Methods, method)
})
// spew.Dump(res)
spew.Dump(res)
return &res, nil
}

View File

@@ -46,6 +46,8 @@ func (c *Class) GetOutFile() (*os.File, error) {
filename := fmt.Sprintf("%s.lua", c.ClassName)
filename = strings.ReplaceAll(filename, " ", "")
filename = strings.ReplaceAll(filename, "-", "")
filename = strings.ReplaceAll(filename, ",", "")
filename = strings.ReplaceAll(filename, ":", "")
f, err := os.Create(filename)
if err != nil {
return nil, err