Skip to content

Instantly share code, notes, and snippets.

@gocs
Last active April 8, 2019 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gocs/98c6317a2e7e071f321a10ed45d6cf61 to your computer and use it in GitHub Desktop.
Save gocs/98c6317a2e7e071f321a10ed45d6cf61 to your computer and use it in GitHub Desktop.
goroutine lifecycle
package main
import (
"fmt"
"time"
)
func sync() {
time.Sleep(time.Second / 2)
fmt.Println("1")
time.Sleep(time.Second)
fmt.Println("3")
time.Sleep(time.Second)
fmt.Println("5")
time.Sleep(time.Second)
}
func main() {
go sync()
fmt.Println("0") // fmt.Println("1")
time.Sleep(time.Second) // time.Sleep(time.Second)
fmt.Println("2") // fmt.Println("3")
time.Sleep(time.Second) // time.Sleep(time.Second)
fmt.Println("4") // fmt.Println("5")
time.Sleep(time.Second) // time.Sleep(time.Second)
fmt.Println("end")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment