Delay calling AfterFunc
go function()
func function() {
// TODO Specific logic
// executed every 5 minutes, recursively calling itself
time.AfterFunc(5*time.Minute, function)
}
Tickers
package main
import "time"
import "fmt"
func main() {
// The mechanism of a punter and a timer is somewhat similar: a channel is used to send data. </span
// Here we use the built-in `range` on this channel to iterate over the values every
// The value sent once in 500ms.
ticker := time.NewTicker(time.Millisecond * 500)
go func() {
for t := range ticker.C {
fmt.Println("Tick at", t)
}
}()
// The punctuator can be stopped in the same way as the timer. </span
// Once a punctuation is stopped, it will no longer be able to receive values from its channel.
// We will stop this punter after 1600ms of running.
time.Sleep(time.Millisecond * 1600)
ticker.Stop()
fmt.Println("Ticker stopped")
}
When we run this program, the dotter will do 3 times before we stop it.
go run tickers.go
Tick at 2012-09-23 11:29:56.487625 -0700 PDT
Tick at 2012-09-23 11:29:56.988063 -0700 PDT
Tick at 2012-09-23 11:29:57.488076 -0700 PDT
Ticker stopped
Read More:
- Python – get the information of calling function from called function
- Deep learning: derivation of sigmoid function and loss function
- Ioremap function and iounmap() function
- error C4996: ‘scanf‘: This function or variable may be unsafe.Visual Studio Series compilers report errors using scanf function
- C / C + + rounding function: round function
- Using curl to generate gnutls_ Handshake() failed: error in the pull function or gnutls recv error: error in the pull function
- Analysis of compilation errors of “error conflicting types for function”
- On and off of timer in JS
- Sigmoid function
- Tensorflow in function tf.Print Method of outputting intermediate value
- pthread_ Introduction and application of join function
- [Warning] incompatible implicit declaration of built-in function ‘strcat’
- MP-BIOS bug: 8254 timer not connected to IO-APIC
- The C language qsort() function reports an error for overflow of – 2147483648 and 2147483648
- geom_ Warning message: sign function’s own error
- “Typeerror: invalid dimensions for image data” in Matplotlib drawing imshow() function
- Reverse function: reverses container contents
- How to use C + + function pointer array
- The function and usage of argc and argv in C language
- error: invalid use of non-static member function