Documentation ¶
Index ¶
- Constants
- func HasCallback(topic string) bool
- func Publish(topic string, args ...interface{})
- func Subscribe(topic string, fn interface{}) error
- func SubscribeAsync(topic string, fn interface{}, transactional bool) error
- func SubscribeOnce(topic string, fn interface{}) error
- func SubscribeOnceAsync(topic string, fn interface{}) error
- func Unsubscribe(topic string, handler interface{}) error
- func WaitAsync()
- type Bus
- func (bus *Bus) HasCallback(topic string) bool
- func (bus *Bus) Publish(topic string, args ...interface{})
- func (bus *Bus) Subscribe(topic string, fn interface{}) error
- func (bus *Bus) SubscribeAsync(topic string, fn interface{}, transactional bool) error
- func (bus *Bus) SubscribeOnce(topic string, fn interface{}) error
- func (bus *Bus) SubscribeOnceAsync(topic string, fn interface{}) error
- func (bus *Bus) Unsubscribe(topic string, handler interface{}) error
- func (bus *Bus) WaitAsync()
- type Client
- type ClientArg
- type ClientService
- type NetworkBus
- type NetworkBusService
- type Server
- type ServerService
- type SubscribeArg
- type SubscribeType
Constants ¶
const (
// PublishService - Client service method
PublishService = "ClientService.PushEvent"
)
const (
// RegisterService - Server subscribe service method
RegisterService = "ServerService.Register"
)
Variables ¶
This section is empty.
Functions ¶
func HasCallback ¶ added in v0.1.0
HasCallback runs HasCallback on package-level bus singleton
func Publish ¶ added in v0.1.0
func Publish(topic string, args ...interface{})
Publish runs Publish on package-level bus singleton
func SubscribeAsync ¶ added in v0.1.0
SubscribeAsync runs SubscribeAsync on package-level bus singleton
func SubscribeOnce ¶
SubscribeOnce runs SubscribeOnce on package-level bus singleton
func SubscribeOnceAsync ¶ added in v0.1.0
SubscribeOnceAsync runs SubscribeOnceAsync on package-level bus singleton
func Unsubscribe ¶ added in v0.1.0
Unsubscribe runs Unsubscribe on package-level bus singleton
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus - box for handlers and callbacks.
func (*Bus) HasCallback ¶ added in v0.2.0
HasCallback returns true if exists any callback subscribed to the topic.
func (*Bus) Publish ¶ added in v0.2.0
Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.
func (*Bus) Subscribe ¶ added in v0.2.0
Subscribe subscribes to a topic. Returns error if `fn` is not a function.
func (*Bus) SubscribeAsync ¶ added in v0.2.0
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 (*Bus) SubscribeOnce ¶ added in v0.2.0
SubscribeOnce subscribes to a topic once. Handler will be removed after executing. Returns error if `fn` is not a function.
func (*Bus) SubscribeOnceAsync ¶ added in v0.2.0
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 (*Bus) Unsubscribe ¶ added in v0.2.0
Unsubscribe removes callback defined for a topic. Returns error if there are no callbacks subscribed to the topic.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client - object capable of subscribing to a remote event bus
type ClientArg ¶
type ClientArg struct { Args []interface{} Topic string }
ClientArg - object containing event for client to publish locally
type ClientService ¶
type ClientService struct {
// contains filtered or unexported fields
}
ClientService - service object listening to events published in a remote event bus
type NetworkBus ¶
NetworkBus - object capable of subscribing to remote event buses in addition to remote event buses subscribing to it's local event bus. Composed of a server and client
func NewNetworkBus ¶
func NewNetworkBus(address, path string) *NetworkBus
NewNetworkBus - returns a new network bus object at the server address and path
func (*NetworkBus) Start ¶
func (networkBus *NetworkBus) Start() error
Start - helper method to serve a network bus service
func (*NetworkBus) Stop ¶
func (networkBus *NetworkBus) Stop()
Stop - signal for the service to stop serving
type NetworkBusService ¶
type NetworkBusService struct {
// contains filtered or unexported fields
}
NetworkBusService - object capable of serving the network bus
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server - object capable of being subscribed to by remote handlers
func (*Server) HasClientSubscribed ¶
func (server *Server) HasClientSubscribed(arg *SubscribeArg) bool
HasClientSubscribed - True if a client subscribed to this server with the same topic
type ServerService ¶
type ServerService struct {
// contains filtered or unexported fields
}
ServerService - service object to listen to remote subscriptions
func (*ServerService) Register ¶
func (service *ServerService) Register(arg *SubscribeArg, success *bool) error
Register - Registers a remote handler to this event bus for a remote subscribe - a given client address only needs to subscribe once event will be republished in local event bus
type SubscribeArg ¶
type SubscribeArg struct { ClientAddr string ClientPath string ServiceMethod string SubscribeType SubscribeType Topic string }
SubscribeArg - object to hold subscribe arguments from remote event handlers
type SubscribeType ¶
type SubscribeType int
SubscribeType - how the client intends to subscribe
const ( // SubscribeTypePermanent - subscribe to all events SubscribeTypePermanent SubscribeType = iota // SubscribeTypeOnce - subscribe to only one event SubscribeTypeOnce )