Last active
September 27, 2021 13:38
-
-
Save Israel-Miles/6aa71bdaaa5316b645f09c64c5024589 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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