Created
July 4, 2018 05:43
-
-
Save ksakae1216/0a3d7bf520c67d2a5fc642c566b8d0ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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