Newer
Older
01_hello / goroutine / channel2.go
yhornisse on 9 Oct 2021 250 bytes add channel sample2
package main

import (
	"fmt"
	"time"
)

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