...

/

Introduction to Goroutines

Introduction to Goroutines

Let's get started with concurrency in Go by learning the basics of goroutines!

A goroutine is a function or a method which is executed concurrently with the rest of the program.

Syntax

You can create a goroutine by using the following syntax:

Yes, it is that simple!

The current goroutine evaluates the input parameters to the functions/methods which are executed in the new goroutines. Even our main() function is a goroutine which was invoked by the implicitly created goroutine managed by Go runtime.

Example

Let’s look at an example:

Go (1.6.2)
package main
import "fmt"
func WelcomeMessage(){
fmt.Println("Welcome to Educative!")
}
func main() {
go WelcomeMessage()
fmt.Println("Hello World!")
}

You can never be sure about the ...