1 Star 0 Fork 0

c01dface/s-go-example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tickers.go 821 Bytes
一键复制 编辑 原始数据 按行查看 历史
c01dface 提交于 2024-12-05 15:03 . add tickers.go
package main
// tickers are for when you want to do something repeatedly at regular
// intervals. Here's an example of a ticker that ticks periodically
// until we stop it.
import (
"fmt"
"time"
)
func main() {
// Tickers use a similar mechanism to timers: a channel that
// is sent values. Here we'll use the select builtin on the
// channel to await the values as they arrive every 500ms
ticker := time.NewTicker(500 * time.Millisecond)
done := make(chan bool)
go func() {
for {
select {
case <-done:
return
case t := <-ticker.C:
fmt.Println("Tick at", t)
}
}
}()
// Tickers can be stopped like timers. Once a ticker is stopped
// it won't receive any more values on its channel.
time.Sleep(1600 * time.Millisecond)
ticker.Stop()
done <- true
fmt.Println("Ticker stopped")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vmalloc/s-go-example.git
git@gitee.com:vmalloc/s-go-example.git
vmalloc
s-go-example
s-go-example
master

搜索帮助