I am basically looking for Nim's alternative to Go's `WaitGroup` package main import ( "fmt" "sync" "time" ) func main() { messages := make(chan int) var wg sync.WaitGroup // you can also add these one at // a time if you need to wg.Add(3) go func() { defer wg.Done() time.Sleep(time.Second * 3) messages <- 1 }() go func() { defer wg.Done() time.Sleep(time.Second * 2) messages <- 2 }() go func() { defer wg.Done() time.Sleep(time.Second * 1) messages <- 3 }() go func() { for i := range messages { fmt.Println(i) } }() wg.Wait() } Run
Here, I create a `WaitGroup` called `wg` and add 3 to it, knowing that I will be calling 3 coroutines. At the end of each coroutines I'd send a signal to `wg` to mark an end of a coroutine. Lastly I would call `Wait` on the WG and it'll make the program wait for all those coroutines to finish.