Skip to content

Commit

Permalink
feat: implement wait group
Browse files Browse the repository at this point in the history
  • Loading branch information
RealYukiSan committed Mar 19, 2023
1 parent 2e38ab1 commit 1be7a66
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
24 changes: 24 additions & 0 deletions fundamental/wait_group.go
@@ -0,0 +1,24 @@
package fundamental

import (
"fmt"
"sync"
)

func ImplementWaitGroup() {
var wg sync.WaitGroup

for i := 0; i < 5; i++ {
var data = fmt.Sprintf("data %d", i)

wg.Add(1)
go doPrint(&wg, data)
}

wg.Wait()
}

func doPrint(wg *sync.WaitGroup, message string) {
defer wg.Done()
fmt.Println(message)
}
14 changes: 9 additions & 5 deletions main.go
@@ -1,12 +1,16 @@
package main

import (
"explore-go/practice"
"fmt"
"explore-go/fundamental"
"runtime"
)

func main() {
go practice.RestFulAPIServer()
practice.HttpClient()
fmt.Scanln()
runtime.GOMAXPROCS(2)

fundamental.ImplementWaitGroup()

// go practice.RestFulAPIServer()
// practice.HttpClient()
// fmt.Scanln()
}

0 comments on commit 1be7a66

Please sign in to comment.