“Golang WaitGroup” Respostas de código

Golang WaitGroup

package main

import (
    "fmt"
    "sync"
    "time"
)

func worker(id int) {
    fmt.Printf("Worker %d starting\n", id)

    time.Sleep(time.Second)
    fmt.Printf("Worker %d done\n", id)
}

func main() {

    var wg sync.WaitGroup

    for i := 1; i <= 5; i++ {
        wg.Add(1)

        i := i

        go func() {
            defer wg.Done()
            worker(i)
        }()
    }

    wg.Wait()

}
Nice Newt

Golang WaitGroup

var wg sync.WaitGroup

for i := 1; i <= 5; i++ {
	wg.Add(1)
	go func(wg *sync.WaitGroup) {
		wg.Done()
	}()
}

wg.Wait()
Navid2zp

Respostas semelhantes a “Golang WaitGroup”

Perguntas semelhantes a “Golang WaitGroup”

Procure respostas de código populares por idioma

Procurar outros idiomas de código