SoFunction
Updated on 2025-03-05

Common ways to use timer in go language

This article summarizes the common ways to use timer in the go language. Share it for your reference. The specific analysis is as follows:

The following three pieces of code (A, b, C) functions are all go language codes for executing the specified function after 5 minutes:

Copy the codeThe code is as follows:
// (A)
(5 * , func() {
    ("expired")
}
// (B) create a Timer object
timer := (5 * )
<-
("expired")
// (C) () returns internally
<-(5 * )
("expired")

I hope this article will be helpful to everyone's Go language programming.