golang 等待5秒执行func
你可以使用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/eqYj 著作权归作者所有。请勿转载和采集!