Skip to content

Instantly share code, notes, and snippets.

@ksakae1216
Created July 4, 2018 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksakae1216/0a3d7bf520c67d2a5fc642c566b8d0ea to your computer and use it in GitHub Desktop.
Save ksakae1216/0a3d7bf520c67d2a5fc642c566b8d0ea to your computer and use it in GitHub Desktop.
package funcpkg
import (
"fmt"
"time"
)
// GoroutinFunc ゴルーチンのサンプルです
func GoroutinFunc() {
fmt.Println("GoroutinFunc 開始")
fmt.Println("関数を実行します")
sampleFunc()
fmt.Println("ゴルーチンで関数を実行します")
go sampleFunc()
time.Sleep(1 * time.Second) // すぐ終わっちゃうのでゴルーチン用に1秒待つ
fmt.Println("GoroutinFunc 終了")
}
func sampleFunc() {
functions := []string{"処理1", "処理2", "処理3", "処理4"}
for _, val := range functions {
fmt.Println(val)
time.Sleep(1 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment