Skip to content

Instantly share code, notes, and snippets.

@Israel-Miles
Last active September 27, 2021 13:38
Show Gist options
  • Save Israel-Miles/6aa71bdaaa5316b645f09c64c5024589 to your computer and use it in GitHub Desktop.
Save Israel-Miles/6aa71bdaaa5316b645f09c64c5024589 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
"sync"
)
func main() {
var wg sync.WaitGroup
start := time.Now()
for i := 1; i <= 10; i++ {
wg.Add(1)
go executeTask(i, &wg)
}
wg.Wait()
fmt.Println("Total execution time:", time.Since(start))
}
func executeTask(i int, wg *sync.WaitGroup) {
defer wg.Done()
fmt.Println("Executing task", i)
time.Sleep(250 * time.Millisecond)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment