9951 explained code solutions for 126 technologies


golangGoroutine example usage


func main() {
  go func() {
    // do something in background
  }()
}ctrl + c
func main() {

declare main function that will be launched automatically

go

execute given function in parallel

func() {

anonymous function to execute in background


Usage example

package main

import "fmt"
import "time"

func hi(name string, sleep int) {
  time.Sleep(time.Duration(sleep) * 1000 * time.Millisecond)
  fmt.Println("Hi, " + name + "!")
}

func main() {
  go hi("Donald", 2)
    hi("Joe", 1)
    time.Sleep(time.Second)
}
output
Hi, Joe!
Hi, Donald!