Go语言休眠sleep

time标准库中的sleep可以休眠程序,阻塞线程。

package main

import (
	"time"
)

func main() {
    
    
	// 休眠1秒
	time.Sleep(time.Duration(1) * time.Second)
	// 休眠30毫秒
	time.Sleep(time.Duration(30) * time.Millisecond)
	// 休眠1小时
	time.Sleep(time.Duration(1) * time.Hour)
}

参考

https://pkg.go.dev/time#Sleep

猜你喜欢

转载自blog.csdn.net/lilongsy/article/details/129263616