wait for threads to complete

This commit is contained in:
2023-07-30 00:43:34 +02:00
parent b2bd683e08
commit ccdf8c03ee
2 changed files with 11 additions and 0 deletions

View File

@@ -4,6 +4,9 @@ import (
"fmt"
)
var threadCount = 0
var threadChan = make(chan bool)
func ArThread(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 1, got " + fmt.Sprint(len(args)), EXISTS: true}
@@ -36,8 +39,13 @@ func ArThread(args ...any) (any, ArErr) {
}
hasrun = true
go func() {
threadCount++
resp, err = runCall(call{Callable: tocall, Args: []any{}}, nil, 0)
wg <- true
threadCount--
if threadCount == 0 {
threadChan <- true
}
}()
return nil, ArErr{}
}},