From 22dd9e85fcd899a4521ca2358e2310fc04998cbf Mon Sep 17 00:00:00 2001 From: unwox Date: Fri, 27 Sep 2024 15:32:48 +0600 Subject: wait till all workers start before starting repl --- main.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index 9a2ad52..677de94 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "runtime" "runtime/cgo" "strings" + "sync" "time" _ "github.com/mattn/go-sqlite3" @@ -341,6 +342,8 @@ func main() { module["http"] = httpModule module["db"] = dbModule + wg := sync.WaitGroup{} + wg.Add(*wrksNum) // start workers for i := 0; i < *wrksNum; i++ { wrk := NewWorker() @@ -352,10 +355,12 @@ func main() { } wrks = append(wrks, wrk) log.Printf("worker %d started\n", i) + wg.Add(-1) wrk.Listen(msgs) }() defer wrk.Stop() } + wg.Wait() // listen for evals from stdio go func () { -- cgit v1.2.3