Understanding goroutines
Goroutines are functions created and scheduled to be run independently by the Go scheduler. The Go scheduler is responsible for the management and execution of goroutines.
Behind the scenes, we have a complex algorithm to make goroutines work. Fortunately, in Golang, we can achieve this highly complex operation with simplicity using the go
keyword.
Note
If you are accustomed to a language that has the async
/await
feature, you probably are used to deciding your function beforehand. It will be used concurrently to change the function signature to sign that the function can be paused/resumed. Calling this function also needs a special notation. When using goroutines, there is no need to change the function signature.
In the following snippets, we have a main function calling sequentially the say
function, passing as an argument "hello"
and "
world"
, respectively:
func main() { say(«hello») say...