Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Channel capacity - buffered channel

package main

import (
	"fmt"
	"time"
)

func sleep() {
	time.Sleep(1000000000)
	fmt.Println("woke up")
}

func main() {
	ch := make(chan string, 2)
	// go sleep()
	ch <- "One"
	ch <- "Two"
	//  ch <- "Three"

	text := <-ch
	fmt.Println(text)

	fmt.Println(<-ch)

	//	fmt.Println(<-ch)
}