Skip to content

Instantly share code, notes, and snippets.

@prabaprakash
Created January 13, 2020 20:45
Show Gist options
  • Save prabaprakash/d3f192587cd86477d558921f8295b056 to your computer and use it in GitHub Desktop.
Save prabaprakash/d3f192587cd86477d558921f8295b056 to your computer and use it in GitHub Desktop.

Revisions

  1. prabaprakash created this gist Jan 13, 2020.
    26 changes: 26 additions & 0 deletions goroutine.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    package main

    import (
    "fmt"
    "time"
    "sync"
    )

    var wg sync.WaitGroup


    func say(s string) {
    for i := 0; i < 5; i++ {
    time.Sleep(100 * time.Millisecond)
    fmt.Println(s)
    }
    wg.Done() // <=> wg.Add(-1)
    }

    func main() {
    wg.Add(2) // register two tasks.
    go say("world")
    say("hello")
    fmt.Println("re")
    wg.Wait()
    }