go的timer

版权声明:本文为博主原创文章,转载时请务必注明本文地址, 禁止用于任何商业用途, 否则会用法律维权。 https://blog.csdn.net/stpeace/article/details/83588490

       看程序:

package main

import (
	"fmt"
    "time"
)

func main() {
	time.AfterFunc(3 * time.Second, func() {fmt.Println("come here 1")})

	timer := time.NewTimer(4 * time.Second)
	<-timer.C
	fmt.Println("come here 2")

	<-time.After(5 * time.Second)
	fmt.Printf("come here 3")

	for {}
}

        一目了然。

猜你喜欢

转载自blog.csdn.net/stpeace/article/details/83588490