Skip to content

Instantly share code, notes, and snippets.

@chouaibhm
Forked from hahwul/concurrency.go
Created October 2, 2021 10:48
Show Gist options
  • Save chouaibhm/a21e071567ccd7e33cf43a07f0f7ee32 to your computer and use it in GitHub Desktop.
Save chouaibhm/a21e071567ccd7e33cf43a07f0f7ee32 to your computer and use it in GitHub Desktop.
Go concurrency
package main
import (
"fmt"
"strconv"
"sync"
)
func main() {
fmt.Println("vim-go")
wordlists := make(chan string)
// Scanning
concurrency := 10
var wg sync.WaitGroup
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func() {
for word := range wordlists {
fmt.Println(word)
}
wg.Done()
}()
}
for j := 0; j < 100; j++ {
wordlists <- strconv.Itoa(j)
}
close(wordlists)
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment