Golang 等待 5 秒执行函数 - 代码示例
你可以使用 time 包中的 Sleep 函数来等待 5 秒,然后执行你的函数。以下是一个示例代码:
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println('Waiting for 5 seconds...')
time.Sleep(5 * time.Second)
fmt.Println('Executing the function...')
myFunc()
}
func myFunc() {
fmt.Println('This is my function.')
}
在上述代码中,我们使用 time.Sleep 函数等待了 5 秒,然后执行了 myFunc 函数。你可以将 myFunc 替换成你要执行的函数。
希望这可以帮助到你!
原文地址: https://www.cveoy.top/t/topic/nRJC 著作权归作者所有。请勿转载和采集!