repl.it
@dorin131/

goroutine

Go

No description

fork
loading
Files
  • main.go
  • Packager files
  • go.mod
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package main

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

func main() {
  wg := sync.WaitGroup{}
  defer wg.Wait()
  for n := range []int{0,1,2,3,4,5,6,7,8,9} {
    wg.Add(1)
    go doInParallel(&wg, n)
  }
}

func doInParallel(wg* sync.WaitGroup, n int) {
  fmt.Println(n)
  time.Sleep(1000 * time.Millisecond)
  defer wg.Done()
}
Fetching token
?