25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

Goroutines in Go

June 4, 2021
Elliot Forbes

Elliot Forbes

Course Instructor

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now.

In this video, we are going to be looking at goroutines in Go and what they are used for.

Overview

package main

import (
	"fmt"
	"time"
)

func HelloWorld(name string) {
	time.Sleep(1 * time.Second)
	fmt.Printf("hello: %s\n", name)
}

func main() {
	go HelloWorld("Elliot")
	fmt.Println("I should be printed first")
	time.Sleep(2 * time.Second)
}

Output

$ go run main.go
I should be printed first
hello: Elliot