Documentation ¶
Index ¶
- type Bus
- type BusController
- type BusPublisher
- type BusSubscriber
- type EventBus
- func (bus *EventBus) HasCallback(topic string) bool
- func (bus *EventBus) Publish(topic string, args ...interface{})
- func (bus *EventBus) PublishWithReply(topic string, timeout time.Duration, args ...interface{}) (interface{}, error)
- func (bus *EventBus) Subscribe(topic string, fn interface{}) error
- func (bus *EventBus) Unsubscribe(topic string, handler interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus interface { BusController BusSubscriber BusPublisher }
Bus englobes global (subscribe, publish, control) bus behavior
type BusController ¶
BusController defines bus control behavior (checking handler's presence, synchronization)
type BusPublisher ¶
type BusPublisher interface { Publish(topic string, args ...interface{}) PublishWithReply(topic string, timeout time.Duration, args ...interface{}) (interface{}, error) // 目前只支持返回一个函数的handler }
BusPublisher defines publishing-related bus behavior
type BusSubscriber ¶
type BusSubscriber interface { Subscribe(topic string, fn interface{}) error Unsubscribe(topic string, handler interface{}) error }
BusSubscriber defines subscription-related bus behavior
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus - box for handlers and callbacks.
func (*EventBus) HasCallback ¶
HasCallback returns true if exists any callback subscribed to the topic.
func (*EventBus) Publish ¶
Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.
func (*EventBus) PublishWithReply ¶
func (bus *EventBus) PublishWithReply(topic string, timeout time.Duration, args ...interface{}) (interface{}, error)
向一个主题推送消息,支持单handler的主题,并返回这个handler的值
func (*EventBus) Subscribe ¶
Subscribe subscribes to a topic. Returns error if `fn` is not a function.
func (*EventBus) Unsubscribe ¶
Unsubscribe removes callback defined for a topic. Returns error if there are no callbacks subscribed to the topic.