mirror of
https://gitee.com/johng/gf.git
synced 2024-12-01 11:48:09 +08:00
29 lines
557 B
Go
29 lines
557 B
Go
|
package main
|
|||
|
|
|||
|
import (
|
|||
|
"fmt"
|
|||
|
"time"
|
|||
|
"gitee.com/johng/gf/g/os/gtime"
|
|||
|
"gitee.com/johng/gf/g/container/gqueue"
|
|||
|
)
|
|||
|
|
|||
|
func main() {
|
|||
|
q := gqueue.New()
|
|||
|
// 数据生产者,每隔1秒往队列写数据
|
|||
|
gtime.SetInterval(time.Second, func() bool {
|
|||
|
for i := 0; i < 10; i++ {
|
|||
|
q.Push(i)
|
|||
|
}
|
|||
|
return true
|
|||
|
})
|
|||
|
|
|||
|
// 消费者,不停读取队列数据并输出到终端
|
|||
|
for {
|
|||
|
if v := q.Pop(); v != nil {
|
|||
|
fmt.Println(" Pop:", v)
|
|||
|
} else {
|
|||
|
break
|
|||
|
}
|
|||
|
}
|
|||
|
}
|