Go (Golang) Advanced Programming
Lab
Lab Manual: Advanced Level Programs
Contents:
1. 1. Goroutines Example
1. Goroutines Example
Code:
package main
import (
"fmt"
"time"
)
func printNumbers() {
for i := 1; i <= 5; i++ {
fmt.Println(i)
time.Sleep(500 * time.Millisecond)
}
}
func main() {
go printNumbers()
time.Sleep(3 * time.Second)
fmt.Println("Main function finished")
}
Output:
1
2
3
4
5
Main function finished