Context is a relatively new component that entered the standard library in version 1.7. It is an interface for synchronization between goroutines that was used internally by the Go team and ended up being a core part of the language.
Understanding context
The interface
The main entity in the package is Context itself, which is an interface. It has only four methods:
type Context interface {
Deadline() (deadline time.Time, ok bool)
Done() <-chan struct{}
Err() error
Value(key interface{}) interface{}
}
Let's learn about these four methods here:
-
Deadline: Returns the time when the context should be cancelled, together with a Boolean that is false when there is no deadline
-
Done: Returns a receive-only...