Quick actions

cmd+k|ctrl+k

Navigation

Languages

Concurrency / Hello World goroutine / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:15:01Z

Updated

2019-03-26T10:15:01Z

package main

import (
	"fmt"
	"time"
)

func main() {
	// create new channel of type string
	ch := make(chan string)

	// start new anonymous goroutine
	go func() {
		time.Sleep(time.Second)
		// send "Hello World" to channel
		ch <- "Hello World"
	}()
	// read from channel
	msg, ok := <-ch
	fmt.Printf("msg='%s', ok='%v'\n", msg, ok)
}
INFO