Documentation
¶
Index ¶
- type Config
- type EventEmitter
- func (c *EventEmitter[T, S]) CountSubscriberByTopic(topic string) int
- func (c *EventEmitter[T, S]) GetTopicsBySubscriber(suber S) []string
- func (c *EventEmitter[T, S]) NewSubscriber(id T) Subscriber[T]
- func (c *EventEmitter[T, S]) Publish(topic string, msg any)
- func (c *EventEmitter[T, S]) Subscribe(suber S, topic string, f func(msg any))
- func (c *EventEmitter[T, S]) UnSubscribe(suber S, topic string)
- func (c *EventEmitter[T, S]) UnSubscribeAll(suber S)
- type Metadata
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventEmitter ¶
type EventEmitter[T comparable, S Subscriber[T]] struct { // contains filtered or unexported fields }
EventEmitter T: 订阅ID模板类型 S: 订阅者模板类型 T:subscription id template type S:subscriber template type
func New ¶
func New[T comparable, S Subscriber[T]](conf *Config) *EventEmitter[T, S]
New 创建事件发射器实例 Creating an EventEmitter Instance
func (*EventEmitter[T, S]) CountSubscriberByTopic ¶
func (c *EventEmitter[T, S]) CountSubscriberByTopic(topic string) int
CountSubscriberByTopic 获取主题订阅人数 Get the number of subscribers to a topic
func (*EventEmitter[T, S]) GetTopicsBySubscriber ¶ added in v0.1.0
func (c *EventEmitter[T, S]) GetTopicsBySubscriber(suber S) []string
GetTopicsBySubscriber 通过订阅者获取主题列表 Get a list of topics by subscriber
func (*EventEmitter[T, S]) NewSubscriber ¶
func (c *EventEmitter[T, S]) NewSubscriber(id T) Subscriber[T]
NewSubscriber 创建一个订阅者, 订阅Id需要保证唯一. Create a subscriber, the subscription id needs to be unique.
func (*EventEmitter[T, S]) Publish ¶
func (c *EventEmitter[T, S]) Publish(topic string, msg any)
Publish 发布消息到指定主题 Post a message to the topic.
func (*EventEmitter[T, S]) Subscribe ¶
func (c *EventEmitter[T, S]) Subscribe(suber S, topic string, f func(msg any))
Subscribe 订阅主题消息. 注意: 回调函数必须是非阻塞的. Subscribe messages from the topic. Note: Callback functions must be non-blocking.
func (*EventEmitter[T, S]) UnSubscribe ¶
func (c *EventEmitter[T, S]) UnSubscribe(suber S, topic string)
UnSubscribe 取消订阅一个主题 Cancel a subscribed topic
func (*EventEmitter[T, S]) UnSubscribeAll ¶
func (c *EventEmitter[T, S]) UnSubscribeAll(suber S)
UnSubscribeAll 取消订阅所有主题 Cancel all subscribed topics
type Subscriber ¶ added in v0.1.0
type Subscriber[T comparable] interface { // GetSubscriberID 获取订阅者唯一ID // Get subscriber unique ID GetSubscriberID() T // GetMetadata 获取元数据 // Getting Metadata GetMetadata() Metadata }