Newer
Older
01_hello / goroutine / channel.go
yhornisse on 9 Oct 2021 293 bytes add channel sample
package main

import (
	"fmt"
	"time"
)

func hoge(done chan int64) { // chan int64 type
	for i := 0; i < 5; i++ {
		fmt.Println(i)
		time.Sleep(1 * time.Second)
	}
	done <- 10 // send
}

func main() {
	done := make(chan int64)
	go hoge(done)
	x := <- done // receicve
	fmt.Println(x) // 10
}