Starting a goroutine

Asynchronous operations

import (
    "fmt"
    "strconv"
    "time"
)

func add(a, b int) int {
    time.Sleep(100 * time.Millisecond)
    return a + b
}

func startGoroutine() {
    result := add(3, 5)
    fmt.Println("result: " + strconv.Itoa(result))
}

go startGoroutine()
fmt.Println("main thread")

// main must outlive the goroutine, otherwise the program
// ends before "result: 8" is printed
time.Sleep(time.Second)
//output:
//main thread
//result: 8