event

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

func Publish

func Publish(topic string, data interface{})

func Subscribe

func Subscribe(topic string, callback Handler)

func Unsubscribe

func Unsubscribe(topics ...string)

Types

type Bus

type Bus struct {
	// contains filtered or unexported fields
}

Bus 存储有关订阅者感兴趣的特定主题的信息

func NewBus

func NewBus(filters ...Filter) *Bus

func (*Bus) Close

func (b *Bus) Close()

安全释放

func (*Bus) Publish

func (b *Bus) Publish(topic string, data interface{})

发布

func (*Bus) Subscribe

func (b *Bus) Subscribe(topic string, callback Handler) *Token

订阅

func (*Bus) Unsubscribe

func (b *Bus) Unsubscribe(topics ...string)

退订

type Event

type Event struct {
	Type string
	Data interface{}
}

type Filter

type Filter func(pTopic, sTopic string) bool

是否发布数据到对应订阅的过滤器 pTopic 发布的主题 sTopic 订阅的主题

type Handler

type Handler func(event Event)

处理事件的回调方法

type Logger

type Logger interface {
	Error(args ...interface{})
}
var (
	DefaultLogger Logger = log.New()
)

type Token

type Token struct {
	// contains filtered or unexported fields
}

func (*Token) Close

func (t *Token) Close()

func (*Token) Done

func (t *Token) Done()

func (*Token) Error

func (t *Token) Error() error

func (*Token) IsClose

func (t *Token) IsClose() bool

Jump to

Keyboard shortcuts

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