Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "time"
  5.  
  6. "github.com/docker/docker/pkg/pubsub"
  7. )
  8.  
  9. func main() {
  10. pub := pubsub.NewPublisher(0, 1)
  11. sub := pub.Subscribe()
  12.  
  13. go func() {
  14. for i := 0; i < 10; i++ {
  15. pub.Publish(i)
  16. time.Sleep(time.Millisecond * 500)
  17. }
  18. pub.Evict(sub)
  19. }()
  20.  
  21. for {
  22. select {
  23. case i, ok := <-sub:
  24. if !ok {
  25. return
  26. }
  27.  
  28. println(i.(int))
  29. time.Sleep(time.Second)
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement