main.go 553 B

123456789101112131415161718192021222324252627282930313233
  1. package main
  2. import (
  3. "log"
  4. "time"
  5. "github.com/ably/ably-go/ably"
  6. )
  7. func main() {
  8. opt := &ably.ClientOptions{}
  9. opt.Key = "kY92tg.1qo8DQ:CS755GfXwEGtBiIr"
  10. a, err := ably.NewRealtimeClient(opt)
  11. panicIfErr(err)
  12. chn := a.Channels.Get("test")
  13. sub, err := chn.Subscribe()
  14. panicIfErr(err)
  15. for {
  16. select {
  17. case m := <-sub.MessageChannel():
  18. log.Println("Received:", m.Data)
  19. case <-time.After(4 * time.Second): // This will reset each pass
  20. log.Println("timeout")
  21. }
  22. }
  23. }
  24. func panicIfErr(err error) {
  25. if err != nil {
  26. panic(err)
  27. }
  28. }