41 lines
642 B
Go
41 lines
642 B
Go
package compiler
|
|
|
|
import "sync"
|
|
|
|
// Compile compiles all the functions.
|
|
func Compile(directory string) (map[string]*Function, error) {
|
|
functions, errors := Scan(directory)
|
|
wg := sync.WaitGroup{}
|
|
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
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
function.Compile()
|
|
}()
|
|
|
|
allFunctions[function.Name] = function
|
|
}
|
|
}
|
|
|
|
wg.Wait()
|
|
return allFunctions, nil
|
|
}
|