From the course: Go Practice: Functions

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Goroutines and channels

Goroutines and channels - Go Tutorial

From the course: Go Practice: Functions

Goroutines and channels

- [Instructor] So far, the functions we've been using have been running consecutively or executing only once the previous function has completed. One of the greatest advantages of Go is its ability to easily and efficiently handle concurrency. Let's explore this further. You can start goroutines which execute a given function by placing the go keyword in front of the invocation. It's that easy. Starting a goroutine is a non-blocking operation so the main goroutine which is executing the main function will not be blocked until the myFunc function completes in its child goroutine. They can be used with both anonymous and named functions. In fact, this example will most likely be broken since the main goroutine will end before any of the implementation code of the myFunc function executes. Instead, we need to use a synchronization mechanism. Channels are a powerful synchronization mechanism which serves the dual purpose of…

Contents