As we could see the function createPizza take 1 second to finish so to have 3 pizzas our program take 3 seconds to do it.

How could we improve our program in order to have the 3 pizzas in the same time that is created just 1 now?

The answer is creating pizzas at the same time. That is the kind of problem that goroutines was design to solve, below the goroutines definition:

A goroutine is a function that is capable of running concurrently with other functions. To create a goroutine we use the keyword go followed by a function invocation.

Knowing now the definition of goroutines, it is possible assume that we could use goroutines to prepare the pizzas at the same time as showed in the code below:

The output of this program is:

Created Pizza 0

Created Pizza 1

Created Pizza 2

Build Pizzas took 1.001509308s