01 exercises hello

https://github.com/andcloudio/go-concurrency-exercises/tree/master/01-exercise-solution

1. hello.go ( https://go.dev/play/p/Hxmdr9WLltc )

package main
import (
    "fmt"
    "time"
)
func fun(s string) {
    for i := 0; i < 3; i++ {
        fmt.Println(s)
        time.Sleep(1 * time.Millisecond)
    }
}
func main() {
    // Direct call
    fun("direct call")

    // write goroutine with different variants for function call.

    // goroutine function call
    go fun("goroutine-1")

    // goroutine with anonymous function
    go func() {
        fun("goroutine-2")
    }()

    // goroutine with function value call
    fv := fun
    go fv("goroutine-3")

    // wait for goroutines to end
    fmt.Println("waiting for goroutines to complete..")
    time.Sleep(1 * time.Second)

    fmt.Println("done..")
}
© Kimi Tsai all right reserved.            Updated : 2023-07-12 09:04:54

results matching ""

    No results matching ""

    results matching ""

      No results matching ""