Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Go supports concurency by the use of the go command. All go functions in the background will terminate when the main terminates.

Code Block
package main
  
import (
  "fmt"
)

func main(){

  //run in background
  go count("sheep")

  go count("fish")

  //wait for keyboard press before exiting
  fmt.Scanln()

}

func count(thing string) {
  for i:=0; true; i++ {
    fmt.Println(i, thing)
    time.Sleep(time.Millisecond * 500)
  }
}

...