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.

Revisions

  1. @hahwul hahwul created this gist Jan 22, 2021.
    32 changes: 32 additions & 0 deletions concurrency.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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()
    }