#Golang-Conccurent

2 articles

Getting to Know Package Context With Cancel On Golang

Getting to Know Package Context With Cancel On Golang

Package introduction context.WithCancel

Context which can add values, we can also add cancel signals to the context. Usually context cancel is used when we need to run another process, and we want to cancel the process. This context cancel is usually run using a different goroutine so that we easily want to cancel the execution of the goroutine, so we just send a cancel signal to the context then the goroutine we want to stop can be done.

Usage Channel Select Range Timeout

Usage Channel Select Range Timeout

The existence of channels really helps us to manage the goroutines that are running in our program. There are times when we also need to manage many goroutines and many channels are needed. So, this is where select comes in handy. select allows us to control data communication through channels. It is used in the same way as the switch selection condition.