EventBus: github.com/asaskevich/EventBus Index | Files

package EventBus

import "github.com/asaskevich/EventBus"

Index

Package Files

client.go event_bus.go network_bus.go server.go

Constants

const (
    // PublishService - Client service method
    PublishService = "ClientService.PushEvent"
)
const (
    // RegisterService - Server subscribe service method
    RegisterService = "ServerService.Register"
)

type Bus Uses

type Bus interface {
    BusController
    BusSubscriber
    BusPublisher
}

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

func New Uses

func New() Bus

New returns new EventBus with empty handlers.

type BusController Uses

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

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

type BusPublisher Uses

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

BusPublisher defines publishing-related bus behavior

type BusSubscriber Uses

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

BusSubscriber defines subscription-related bus behavior

type Client Uses

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

Client - object capable of subscribing to a remote event bus

func NewClient Uses

func NewClient(address, path string, eventBus Bus) *Client

NewClient - create a client object with the address and server path

func (*Client) EventBus Uses

func (client *Client) EventBus() Bus

EventBus - returns the underlying event bus

func (*Client) Start Uses

func (client *Client) Start() error

Start - starts the client service to listen to remote events

func (*Client) Stop Uses

func (client *Client) Stop()

Stop - signal for the service to stop serving

func (*Client) Subscribe Uses

func (client *Client) Subscribe(topic string, fn interface{}, serverAddr, serverPath string)

Subscribe subscribes to a topic in a remote event bus

func (*Client) SubscribeOnce Uses

func (client *Client) SubscribeOnce(topic string, fn interface{}, serverAddr, serverPath string)

SubscribeOnce subscribes once to a topic in a remote event bus

type ClientArg Uses

type ClientArg struct {
    Args  []interface{}
    Topic string
}

ClientArg - object containing event for client to publish locally

type ClientService Uses

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

ClientService - service object listening to events published in a remote event bus

func (*ClientService) PushEvent Uses

func (service *ClientService) PushEvent(arg *ClientArg, reply *bool) error

PushEvent - exported service to listening to remote events

type EventBus Uses

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

EventBus - box for handlers and callbacks.

func (*EventBus) HasCallback Uses

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

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

func (*EventBus) Publish Uses

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

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

func (*EventBus) Subscribe Uses

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

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

func (*EventBus) SubscribeAsync Uses

func (bus *EventBus) SubscribeAsync(topic string, 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 Uses

func (bus *EventBus) 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 (*EventBus) SubscribeOnceAsync Uses

func (bus *EventBus) SubscribeOnceAsync(topic string, 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 Uses

func (bus *EventBus) 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 (*EventBus) WaitAsync Uses

func (bus *EventBus) WaitAsync()

WaitAsync waits for all async callbacks to complete

type NetworkBus Uses

type NetworkBus struct {
    *Client
    *Server
    // contains filtered or unexported fields
}

NetworkBus - object capable of subscribing to remote event buses in addition to remote event busses subscribing to it's local event bus. Compoed of a server and client

func NewNetworkBus Uses

func NewNetworkBus(address, path string) *NetworkBus

NewNetworkBus - returns a new network bus object at the server address and path

func (*NetworkBus) EventBus Uses

func (networkBus *NetworkBus) EventBus() Bus

EventBus - returns wrapped event bus

func (*NetworkBus) Start Uses

func (networkBus *NetworkBus) Start() error

Start - helper method to serve a network bus service

func (*NetworkBus) Stop Uses

func (networkBus *NetworkBus) Stop()

Stop - signal for the service to stop serving

type NetworkBusService Uses

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

NetworkBusService - object capable of serving the network bus

type Server Uses

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

Server - object capable of being subscribed to by remote handlers

func NewServer Uses

func NewServer(address, path string, eventBus Bus) *Server

NewServer - create a new Server at the address and path

func (*Server) EventBus Uses

func (server *Server) EventBus() Bus

EventBus - returns wrapped event bus

func (*Server) HasClientSubscribed Uses

func (server *Server) HasClientSubscribed(arg *SubscribeArg) bool

HasClientSubscribed - True if a client subscribed to this server with the same topic

func (*Server) Start Uses

func (server *Server) Start() error

Start - starts a service for remote clients to subscribe to events

func (*Server) Stop Uses

func (server *Server) Stop()

Stop - signal for the service to stop serving

type ServerService Uses

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

ServerService - service object to listen to remote subscriptions

func (*ServerService) Register Uses

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 Uses

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 Uses

type SubscribeType int

SubscribeType - how the client intends to subscribe

const (
    // Subscribe - subscribe to all events
    Subscribe SubscribeType = iota
    // SubscribeOnce - subscribe to only one event
    SubscribeOnce
)

Package EventBus imports 7 packages (graph) and is imported by 14 packages. Updated 2018-03-18. Refresh now. Tools for package owners.