ARTICLE AD BOX
If I want to do 2 tasks and wait until both are done, is it better to run both in their own goroutines and parent waits (2 work + 1 waits), or run just one of them in background and make the parent do the work of task2 and wait for task1? It looks the same but way1 uses 1 less goroutine.
func way1() { done := make(chan bool) go func() { task1() done <- true }() task2() <-done // both done } func way2() { var wg sync.WaitGroup wg.Go(func() { task1() }) wg.Go(func() { task2() }) wg.Wait() // both done }