Skip to content

Instantly share code, notes, and snippets.

@hahwul
Created January 22, 2021 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hahwul/e723ac6847c33be0c5a59e04b60fb35c to your computer and use it in GitHub Desktop.
Save hahwul/e723ac6847c33be0c5a59e04b60fb35c 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