event

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

type Broker interface {
	Subscribe(ctx context.Context) (EventSource, error)
	Unsubscribe(src EventSource) (hasMore bool, err error)
}

Broker provides a friendly interface to fan-out events to as many subscribers registered with it. Notice that an explicit unsubscription is necessary even with a context.Context being sent on the subscription call (to be improved).

func NewBroker

func NewBroker(ctx context.Context, source EventSource) Broker

type BrokerPool

type BrokerPool interface {
	Subscribe(ctx context.Context, id string, factoryArg interface{}) (EventSource, error)
}

BrokerPool manages a group of brokers which can be accessed and retrieved via an ID. It also simplifies the access to the brokers themselves, providing a single Subscribe function which automatically makes the unsubscription when the context is cancelled.

The EventSourceFactory passed as argument to the constructor should create a new EventSource channel, using the optional factoryArg that is passed on subscription.

In the simplest case, for example for messaging events between internal application components, there could be a single set of EventSources and the factory would grab them by their ID and return otherwise return an error for inexistent event source. In more complex scenarios, these event sources could be actual subscriptions to some remote messaging service for example Redis or RabbitMQ.

func NewPool

func NewPool(factory EventSourceFactory) BrokerPool

type Event

type Event struct {
	Type string
	Data interface{}
}

func NewEvent

func NewEvent(data interface{}) Event

func NewTypedEvent

func NewTypedEvent(_type string, data interface{}) Event

type EventSource

type EventSource <-chan Event

type EventSourceFactory

type EventSourceFactory func(ctx context.Context, id string, arg interface{}) (EventSource, error)

Jump to

Keyboard shortcuts

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