Multiply await

Report a typo

In the first example of the theory, you used a single channel to wait for the result:

package main

import (
    "time"
)

func main() {
    sync := make(chan bool, 1)

    go func() {
        time.Sleep(time.Second)
        sync <- true
    }()

    <-sync
}

Using a similar principle, make the parent goroutine wait for the completion of processing of multiple child goroutines. The number of launched goroutines is read from the input.

Write a program in Go
package main

import (
"fmt"
"time"
)

func main() {
var workers int
fmt.Scan(&workers)

sync := make(?, ?)

for w := 0; w < workers; w++ {
go func() {
?
check() // DO NOT delete this line of code, it is used for checking the answer
}()
}

for ? {
?
}

// DO NOT delete the lines below, they are used for checking the answer
time.Sleep(time.Second)
check()
}
___

Create a free account to access the full topic