gf/.example/container/gqueue/gqueue3.go

31 lines
487 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"time"
"github.com/gogf/gf/container/gqueue"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/os/gtimer"
)
func main() {
queue := gqueue.New()
// 数据生产者每隔1秒往队列写数据
gtimer.SetInterval(time.Second, func() {
queue.Push(gtime.Now().String())
})
// 消费者,不停读取队列数据并输出到终端
for {
select {
case v := <-queue.C:
if v != nil {
fmt.Println(v)
} else {
return
}
}
}
}