Documentation ¶
Overview ¶
Example ¶
checker := NewChecker(TimeoutOption(10 * time.Millisecond)) go checker.Run() go func() { upChan := checker.UpChan() downChan := checker.DownChan() for { select { case entry := <-upChan: fmt.Printf("[%v]上线了", entry.K) case entry := <-downChan: fmt.Printf("[%v]下线了\n", entry.K) } } }() for i := 0; i < 10000; i++ { go func(i int) { for k := 0; k < 1000; k++ { checker.Touch(fmt.Sprint(i)) time.Sleep(time.Millisecond * time.Duration(rand.Int31n(20))) } }(i) } time.Sleep(100 * time.Second)
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AliveChecker ¶
type AliveChecker interface { Run() (err error) Touch(identity string) (err error) // UpChan 获取上线消息通道,需要尽快消耗,touch会以非阻塞的方式向此管道发送 UpChan() (upChan <-chan Entry) // DownChan 获取下线消息通道,需要尽快消耗,超过缓冲区后将丢失事件 DownChan() (toChan <-chan Entry) }
func NewChecker ¶
func NewChecker(options ...Option) AliveChecker
Click to show internal directories.
Click to hide internal directories.