chainbus

package
v0.0.0-...-020e20f Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus interface {
	BusController
	ChainSuber
	ChainPuber
}

Bus englobes global (subscribe, publish, control) bus behavior.

func New

func New() Bus

New returns new ChainBus with empty handlers.

type BusController

type BusController interface {
	HasCallback(topic string) bool
	WaitAsync()
}

BusController defines bus control behavior (checking handler's presence, synchronization).

type ChainBus

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

ChainBus - box for handlers and callbacks.

func (*ChainBus) HasCallback

func (bus *ChainBus) HasCallback(topic string) bool

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

func (*ChainBus) Publish

func (bus *ChainBus) Publish(topic string, args ...interface{})

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

func (*ChainBus) Subscribe

func (bus *ChainBus) Subscribe(topic string, fn interface{}) error

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

func (*ChainBus) SubscribeAsync

func (bus *ChainBus) SubscribeAsync(topic string, fn interface{}, transactional bool) error

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

func (*ChainBus) SubscribeOnce

func (bus *ChainBus) SubscribeOnce(topic string, fn interface{}) error

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

func (*ChainBus) SubscribeOnceAsync

func (bus *ChainBus) SubscribeOnceAsync(topic string, fn interface{}) error

SubscribeOnceAsync subscribes to a topic once with an asynchronous callback Async determines whether subsequent Publish should wait for callback return Handler will be removed after executing. Returns error if `fn` is not a function.

func (*ChainBus) Unsubscribe

func (bus *ChainBus) Unsubscribe(topic string, handler interface{}) error

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

func (*ChainBus) WaitAsync

func (bus *ChainBus) WaitAsync()

WaitAsync waits for all async callbacks to complete.

type ChainPuber

type ChainPuber interface {
	Publish(topic string, args ...interface{})
}

ChainPuber defines publishing-related bus behavior.

type ChainSuber

type ChainSuber interface {
	Subscribe(topic string, handler interface{}) error
	SubscribeAsync(topic string, handler interface{}, transactional bool) error
	SubscribeOnce(topic string, handler interface{}) error
	SubscribeOnceAsync(topic string, handler interface{}) error
	Unsubscribe(topic string, handler interface{}) error
}

ChainSuber defines subscribing-related bus behavior.

Jump to

Keyboard shortcuts

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