goroutine1.go 602 B

1234567891011121314151617181920212223242526272829
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. func main() {
  7. fmt.Println("In main()")
  8. // longWait()
  9. go longWait()
  10. // shortWait()
  11. go shortWait()
  12. fmt.Println("About to sleep in main()")
  13. time.Sleep(10 * 1e9) // sleep works with a Duration in nanoseconds (ns) !
  14. fmt.Println("At the end of main()")
  15. }
  16. func longWait() {
  17. fmt.Println("Beginning longWait()")
  18. time.Sleep(5 * 1e9) // sleep for 5 seconds
  19. fmt.Println("End of longWait()")
  20. }
  21. func shortWait() {
  22. fmt.Println("Beginning shortWait()")
  23. time.Sleep(2 * 1e9) // sleep for 2 seconds
  24. fmt.Println("End of shortWait()")
  25. }