eventbus

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventBus

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

EventBus - box for handlers and callbacks.

func (*EventBus) HasCallback

func (bus *EventBus) HasCallback(topic EventTopic) bool

HasCallback returns true if exists any callback subscribed to the topic.

func (*EventBus) Publish

func (bus *EventBus) Publish(topic EventTopic, args ...interface{})

Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.

func (*EventBus) Subscribe

func (bus *EventBus) Subscribe(topic EventTopic, fn interface{}) error

Subscribe subscribes to a topic. Returns error if `fn` is not a function.

func (*EventBus) SubscribeAsyncPool

func (bus *EventBus) SubscribeAsyncPool(topic EventTopic, fn interface{}, transactional bool) error

SubscribeAsync subscribes to a topic with an asynchronous callback Transactional determines whether subsequent callbacks for a topic are run serially (true) or concurrently (false) Returns error if `fn` is not a function.

func (*EventBus) SubscribeOnce

func (bus *EventBus) SubscribeOnce(topic EventTopic, fn interface{}) error

SubscribeOnce subscribes to a topic once. Handler will be removed after executing. Returns error if `fn` is not a function.

func (*EventBus) SubscribeOnceAsync

func (bus *EventBus) SubscribeOnceAsync(topic EventTopic, fn interface{}) error

SubscribeOnceAsync subscribes to a topic once with an asynchronous callback Handler will be removed after executing. Returns error if `fn` is not a function.

func (*EventBus) Unsubscribe

func (bus *EventBus) Unsubscribe(topic EventTopic, handler interface{}) error

Unsubscribe removes callback defined for a topic. Returns error if there are no callbacks subscribed to the topic.

func (*EventBus) WaitAsync

func (bus *EventBus) WaitAsync()

WaitAsync waits for all async callbacks to complete

type EventBusPublisher

type EventBusPublisher interface {
	Publish(topic EventTopic, args ...interface{})
}

BusPublisher defines publishing-related bus behavior

type EventBusSubscriber

type EventBusSubscriber interface {
	Subscribe(topic EventTopic, fn interface{}) error
	//transactional 为true,代表顺序化执行callback
	SubscribeAsyncPool(topic EventTopic, fn interface{}, transactional bool) error
	SubscribeOnce(topic EventTopic, fn interface{}) error
	SubscribeOnceAsync(topic EventTopic, fn interface{}) error
	Unsubscribe(topic EventTopic, handler interface{}) error
}

EventBusSubscriber defines subscription-related bus behavior

type EventTopic

type EventTopic string

type Interface

type Interface interface {
	EventBusSubscriber
	EventBusPublisher

	HasCallback(topic EventTopic) bool
	WaitAsync()
}

EventBus englobes global (subscribe, publish, control) bus behavior

func New

func New(asyncPoolSize int) Interface

New returns new EventBus with empty handlers.

Jump to

Keyboard shortcuts

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