Back to articles
Go Learning Notes - Part 8: Concurrency & Goroutines

Go Learning Notes - Part 8: Concurrency & Goroutines

via Dev.to BeginnersKervie Sazon

Today I explored Concurrency in Go using Goroutines and learned how Go can perform tasks in the background while the program continues executing. In my conference booking application, I implemented a goroutine to simulate sending a ticket confirmation email without blocking the main program. Concurrency in Go Concurrency allows a program to run multiple tasks independently. Go provides a simple way to achieve this using goroutines, which are lightweight threads managed by the Go runtime. Instead of waiting for a task to finish, Go can run it in the background. Goroutines with the go keyword A goroutine is created by adding the go keyword before a function call. In my program, I run the sendTicket function as a goroutine: wg.Add(1) go sendTicket(userTicket, fName, lName, email) This allows the program to continue running other code while the ticket is being "sent". Simulating Work with time.Sleep Inside the sendTicket function, I simulate a delay to represent sending an email. time.Slee

Continue reading on Dev.to Beginners

Opens in a new tab

Read Full Article
3 views

Related Articles