Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "time"
- "github.com/docker/docker/pkg/pubsub"
- )
- func main() {
- pub := pubsub.NewPublisher(0, 1)
- sub := pub.Subscribe()
- go func() {
- for i := 0; i < 10; i++ {
- pub.Publish(i)
- time.Sleep(time.Millisecond * 500)
- }
- pub.Evict(sub)
- }()
- for {
- select {
- case i, ok := <-sub:
- if !ok {
- return
- }
- println(i.(int))
- time.Sleep(time.Second)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement