goalive

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

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

type Entry

type Entry = internal.Entry

type Option

type Option func(conf *checkerConf)

func TimeoutOption

func TimeoutOption(duration time.Duration) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL