I am learning concurrency and I want the following code to output
print in worker function
print in inner anonymous function
Done
Here is the code
package main
import (
"fmt"
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
go worker()
go func() {
defer wg.Done()
fmt.Println("print in inner anonymous function")
}()
}()
wg.Wait()
fmt.Println("Done")
time.Sleep(time.Second)
}
func worker() {
fmt.Println("print in worker function")
}