Go (golang) Tutorials - Concurrency Waitgroups

Опубликовано: 16 Апрель 2018
на канале: Ambasoft Java
976
19

#golang #go #concurrency #waitgroups

Concurrency - WaitGroups
---------------------------
will wait until a collection of goroutines completes their work
Wait groups will block the main routine from execution until all the go routines finishes their work

waidemo.go
-----------
package main
import ("fmt"
"time"
"sync"
)
func display(i int,g *sync.WaitGroup){
fmt.Println("Start",i)
time.Sleep(2*time.Second)
fmt.Println("End",i)
g.Done() //Specify the waitgroup about the completion of a goroutine
}
func main(){
var g sync.WaitGroup
//use for loop {
g.Add(1) //Will create a waitgroup entry for every go routine invocation
go display(i,&g)
}
g.Wait() //Blocking all to ensure main goroutine waits until all the go routines completed
fmt.Println("Exiting Main goroutine")
}


Смотрите видео Go (golang) Tutorials - Concurrency Waitgroups онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Ambasoft Java 16 Апрель 2018. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 976 раз и оно понравилось 19 посетителям.