#Async

6 articles

Recognizing Package Context With Timeout In Golang

Recognizing Package Context With Timeout In Golang

Package introduction context.WithTimeout

In the previous article we learned context.WithCancel where we manually send the cancel signal from context. But we can also add cancel signal to context automatically by using timeout timings. By using timeout, we no longer need to manually call cancel execution, but with timeout cancel will be automatically executed if the timeout time has passed.

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.

Get to know Package Context With Value in Golang

Get to know Package Context With Value in Golang

Introduction to the context.WithValue package

At the beginning of the context explanation, we know that the context will be created for the first time during initialization using context.Background() or context.TODO(), where the context does not have a value, aka it is still empty. We can add values from a context with a concept like a map, namely [key - value].

Getting to Know Package Context in Golang

Getting to Know Package Context in Golang

Introduction to package context

Context is a package that can store and carry data values, timeout signals and deadline signals. This context runs and is created per request. The context usually carries the value from initialization until the end of the process. This context is sometimes a necessity when we code a program so that from the beginning of the function to the next function the previous value can be used if the process in the next function requires data from the initial process.

Get to know the Package Ticker in Golang

Get to know the Package Ticker in Golang

Introduction to the time.Ticker package

This Golang package is a package that is used to repeat certain events which will continue to be repeated for a certain time. When this ticker has expired it will send a trigger or signal to the channel.

Get to know the Package Timer in Golang

Get to know the Package Timer in Golang

Introduction to the time.Timer package

time.Timer is a package that deals with times or events that will occur when the process is executed. For example, we will provide a ‘delay’ for a few seconds to go to the next process or there is another scheme.