Running several goroutines (WaitGroup, ErrGroup)

Using WaitGroup

Report a typo

Below is a snippet of Go code that is missing some elements. This program is designed to run multiple tasks concurrently within a WaitGroup.

Fill in the blanks using the appropriate keywords and methods to make sure the program runs correctly.

Fill in the gaps with the relevant elements
package main

import (
    "fmt"
    ""
)

func main() {
    var wg 

    for i := 0; i < 5; i++ {
        wg.Add(1)
        go func(id int) {
            defer wg.
            fmt.Printf("Goroutine %d is working\n", id)
        }(i)
    }

    wg.()
    fmt.Println("All goroutines have completed.")
}
sync.WaitGroupGroupAdd(-1)sync/waitgroupJoinSleepWaitDone()sync

Create a free account to access the full topic