-
-
Save chouaibhm/a21e071567ccd7e33cf43a07f0f7ee32 to your computer and use it in GitHub Desktop.
Go concurrency
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" | |
| "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