Improved code layout

This commit is contained in:
Eduard Urbach 2024-06-21 12:48:01 +02:00
parent 5cedb516c5
commit 890f782af8
Signed by: eduard
GPG key ID: 49226B848C78F6C8
4 changed files with 133 additions and 110 deletions

51
src/build/compile.go Normal file
View file

@ -0,0 +1,51 @@
package build
import (
"sync"
)
// compile waits for all functions to finish compilation.
func compile(functions <-chan *Function, errors <-chan error) (map[string]*Function, error) {
allFunctions := map[string]*Function{}
for functions != nil || errors != nil {
select {
case err, ok := <-errors:
if !ok {
errors = nil
continue
}
return nil, err
case function, ok := <-functions:
if !ok {
functions = nil
continue
}
allFunctions[function.Name] = function
}
}
wg := sync.WaitGroup{}
for _, function := range allFunctions {
wg.Add(1)
go func() {
defer wg.Done()
function.Compile()
}()
}
wg.Wait()
for _, function := range allFunctions {
if function.Error != nil {
return nil, function.Error
}
}
return allFunctions, nil
}