Learning Golang: Introduction to Concurrency Patterns, goroutines and channels

Mario Carrion • August 12, 2021
Video Thumbnail
Mario Carrion Logo

Mario Carrion

View Channel

About

Welcome👋🏼 Hello! My name is Mario, and I am a Hands-on Software Architect and Lead Backend Engineer with decades of professional experience building all kinds of software, such as on-premise Automation Systems, Linux Accessibility Desktop Applications, Cloud Governance and Compliance Systems, Media Streaming Services, and Highly Scalable Distributed Cloud-based Advertising Systems. I post a new video every other Monday at 09:00 AM Eastern Time. The content I produce includes what I've learned while working for small startups and large companies and the processes I've followed for successfully delivering complex enterprise systems from start to end. Subscribe if you like Software Development, Software Architecture, and Systems Design... and of course, Go! Keep it up. Don't give up!

Video Description

Welcome! Let's learn about Go/Golang Concurrency Patterns, but first let's learn about concurrency in Go/Golang, including goroutines, channels and the different keywords needed: like close, range and select. * What is a goroutine? It is lightweight thread managed by the Go/Golang runtime, independently executed function that has its own call stack. * What is a channel? Is a mechanism through which we can send and receive values, it uses the arrow operator which indicates data flow. By default sender and receiver will block if the other side is not ready * What is a buffered channel? It's a type of buffer that has a length. Sending to a buffered channel will block if it is full and receiving from a buffered channel will only block when it's empty. * What else can we do with channels? There are 3 new keywords applicable to channels: "close", "select" and "range": * "close" allows closing the channel, this means we can't receive or send values to it. * "selects" allows to receive messages from multiple channels via "cases", it's like a "switch", it also supports a "default" value. * "range" is similar to the keyword used when looping through slices/arrays; but in this cases it will continuously receive values from the channel until it gets closed. Recall this is the "Introduction to Concurrency Patterns in Go/Golang", in future episodes I will describe concrete patterns to use when building concurrent programs. --- RELEVANT LINKS * Previous episode: "Learning Golang: Interface Types - Part 2 (empty interface, type assertion and type switches)" https://youtu.be/m14ob5dCLag * Example code: https://github.com/MarioCarrion/videos/tree/8b70c807d63b854cde4dcbf1a1111b856a449cd5/2021/08/12/introductions-concurrency-patterns * Playlist "Software Architecture in Go": https://www.youtube.com/playlist?list=PL7yAAGMOat_GCd12Lrv_evJ3Zhv1dl8B- * Playlist "Learning Go": https://www.youtube.com/playlist?list=PL7yAAGMOat_F7bOImcjx4ZnCtfyNEqzCy * Playlist "Building Microservices in Go": https://www.youtube.com/playlist?list=PL7yAAGMOat_Fn8sAXIk0WyBfK_sT1pohu * Playlist "GoTools and Packages": https://www.youtube.com/playlist?list=PL7yAAGMOat_HEEOvH99agDs_5g51A0Ls3 * Playlist "Testing in Go": https://www.youtube.com/playlist?list=PL7yAAGMOat_HSeW4zF0uRL9EaHadE4ZZq 00:00 Intro 00:16 What is Concurrency? 00:36 What is Parallelism? 00:46 Analogy: Concurrency 01:53 Analogy: Parallelism 02:20 What is a goroutine in Golang? 02:49 Example: goroutine in Golang 04:03 What is channel in Golang? 05:30 Example 1: channels in Golang 06:40 Example 2: channels and goroutines in Golang 08:35 What is a buffered channel in Golang? 09:56 Example: buffered channels in Golang 11:39 Channels: Close, Select and Range in Golang 12:33 Example: goroutines and channels in Golang 17:12 Conclusion: Introduction to Concurrency Patterns in Golang --- Who am I: Hello👋🏼! I'm Mario, a Hands-on Software Architect and Lead Backend Engineer with more than 16 years of professional experience building all kinds of software including on-premise Industrial Automation Systems, Linux Accessibility Desktop and Browser Components as well as Distributed Advertising Microservices. Every week I will share with you different topics I've learned while working for small startups and large companies including the processes I've followed over the years for successfully delivering complex enterprise systems from start to end. Subscribe if you like Software Development, Software Architecture and Systems Design! Keep it up. Don't give up! https://twitter.com/MarioCarrion https://instagram.com/Mario.Carrion #golang #tutorial #concurrency --- Our affiliate links below Shop our Amazon favorites → https://www.amazon.com/shop/rubycarrion Shop my IG feed on my LIKEtoKNOWit (LTK) page → https://www.liketoknow.it/RubyCarrion Shop Top Deals and Featured Offers at Best Buy → https://bestbuy.7tiv.net/c/2558226/687081/10014 Get a 30 day FREE Trial of Epidemic Sound → https://www.epidemicsound.com/referral/szx441/ Try Amazon Prime 30-day FREE Trial → https://amzn.to/3yf9a0f I love getting Cash Back and think you will too! Join for FREE and get $30 when you spend $30. https://www.rakuten.com/r/RUBYRA132?eeid=28187 --- Our Vlog Channel https://www.youtube.com/c/RubyCarrion/videos

You May Also Like

Boost Your Golang Skills

AI-recommended products based on this video

Loading...
TRAUSI HD Webcam with Microphone, Noise Cancellation, Privacy Cover, Wide-Angle Lens, Auto Light Correction, Plug & Play USB Webcam for Laptop, Desktop, PC, Mac, Zoom, Skype, Streaming (1080P, Black)

TRAUSI HD Webcam with Microphone, Noise Cancellation, Privacy Cover, Wide-Angle Lens, Auto Light Correction, Plug & Play USB Webcam for Laptop, Desktop, PC, Mac, Zoom, Skype, Streaming (1080P, Black)

(284)
$27.99
Prime
1K+ bought in past month
Loading...
TRAUSI 1080P HD Webcam with Microphone, Noise Cancellation, Privacy Cover, Wide-Angle Lens, Auto Light Correction, Plug & Play USB Webcam for Laptop, Desktop, PC, Mac, Zoom, Skype, Streaming Black

TRAUSI 1080P HD Webcam with Microphone, Noise Cancellation, Privacy Cover, Wide-Angle Lens, Auto Light Correction, Plug & Play USB Webcam for Laptop, Desktop, PC, Mac, Zoom, Skype, Streaming Black

(205)
$28.99
FREE delivery Wed, Jul 2 on your first order
1K+ bought in past month
Loading...
10Gtek USB WiFi Adapter, for PC, AC600M USB WiFi Dongle 802.11ac Wireless Network Adapter with Dual Band 2.4GHz/5Ghz for Desktop Laptop Support Windows 10/8/7/XP, MAC OS, Linux etc

10Gtek USB WiFi Adapter, for PC, AC600M USB WiFi Dongle 802.11ac Wireless Network Adapter with Dual Band 2.4GHz/5Ghz for Desktop Laptop Support Windows 10/8/7/XP, MAC OS, Linux etc

(11)
$14.95
FREE delivery Sun, Jun 22 on your first order
Loading...
1300Mbps Wireless WiFi Adapter, USB3.0 WiFi Dongle 2.4G/5G 802.11AC Network Adapter Receiver with High Gain Antenna for Desktop Laptop PC, Support Windows 11/10/8/8.1/7/Vista/XP, Mac 10.6-10.15

1300Mbps Wireless WiFi Adapter, USB3.0 WiFi Dongle 2.4G/5G 802.11AC Network Adapter Receiver with High Gain Antenna for Desktop Laptop PC, Support Windows 11/10/8/8.1/7/Vista/XP, Mac 10.6-10.15

(56)
$22.99
FREE delivery Sun, Jun 22 on your first order
100+ bought in past month
Loading...
The Sqirl Jam (Jelly, Fruit Butter, and Others) Book

The Sqirl Jam (Jelly, Fruit Butter, and Others) Book

(183)
$0.00$31.33
Available instantly
Loading...
Cozy Corner: Coloring Book for Adults and Kids

Cozy Corner: Coloring Book for Adults and Kids

(974)
$10.92
FREE delivery Wed, Dec 24 on your first order
Loading...
Hello, Baby Animals: A Durable High-Contrast Black-and-White Board Book for Newborns and Babies

Hello, Baby Animals: A Durable High-Contrast Black-and-White Board Book for Newborns and Babies

(7,613)
$7.17$4.20
FREE delivery Tue, Dec 2 on your first order
Loading...
Little Blue Truck's Halloween: A Fun And Interactive Lift-the-Flap Book For Kids Celebrating Halloween With Little Blue Truck And Friends

Little Blue Truck's Halloween: A Fun And Interactive Lift-the-Flap Book For Kids Celebrating Halloween With Little Blue Truck And Friends

(14,340)
$13.13
FREE delivery Fri, Oct 31 on your first order
Loading...
Asus Vivobook Go 15 Laptop, 15.6” FHD Display, Intel® Core™ i3-N305 Processor, 4GB RAM, 128GB UFS, Windows 11 Home in S Mode, E1504GA-AS32-CA

Asus Vivobook Go 15 Laptop, 15.6” FHD Display, Intel® Core™ i3-N305 Processor, 4GB RAM, 128GB UFS, Windows 11 Home in S Mode, E1504GA-AS32-CA

(77)
$399.00$397.70
FREE delivery Sun, Jun 22
Loading...
ASUS Vivobook Go 12 L210 11.6” Ultra-Thin Laptop, Intel Celeron N4500, 4GB RAM, 64GB eMMC, Windows 11 Home in S Mode Includes 1 Year of Office 365 Personal, L210KA-AS01-CA

ASUS Vivobook Go 12 L210 11.6” Ultra-Thin Laptop, Intel Celeron N4500, 4GB RAM, 64GB eMMC, Windows 11 Home in S Mode Includes 1 Year of Office 365 Personal, L210KA-AS01-CA

(501)
$245.00$239.99
FREE delivery Sun, Aug 10
200+ bought in past month
Loading...
Hand Warmers Rechargeable OUTJUT 2 in 1 USB Pocket-Sized Handwarmers Easy to Carry Electric Hand Warmer 3 Heat Settings Hot Hand Gifts for Men Women Go Out for Hiking Camping Sking and Fishing

Hand Warmers Rechargeable OUTJUT 2 in 1 USB Pocket-Sized Handwarmers Easy to Carry Electric Hand Warmer 3 Heat Settings Hot Hand Gifts for Men Women Go Out for Hiking Camping Sking and Fishing

(18)
$31.37
FREE delivery Sat, Jun 14 on your first order
Loading...
Catit Go Natural Pea Husk Clumping Cat Litter, Unscented, 5.6 kg, Dust Free & Lightweight Cat Litter, Easy to Scoop, Litiere Pour Chat

Catit Go Natural Pea Husk Clumping Cat Litter, Unscented, 5.6 kg, Dust Free & Lightweight Cat Litter, Easy to Scoop, Litiere Pour Chat

(4)
$21.24
FREE delivery Sun, Nov 30 on your first order
400+ bought in past month