eventbus

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(event Event, err error)

Callback is a callback function that is called when an event is processed by the listener.

type Event

type Event interface {
	// ID returns the ID of the event.
	ID() ids.ID
	// Name returns the name of the event.
	Name() EventName
}

type EventBus

type EventBus interface {
	Start() error
	Stop() error
	// Publish publishes an event. Methods can return before the Event is handled.
	Publish(event Event, options ...Option) error

	// Subscribe subscribes to an event.
	// The handler will be called when the event is published.
	// The handler can return an error, which will be returned by the Publish method.
	Subscribe(eventName EventName, handler EventHandler) error
}

EventBus allows to publish and subscribe to events. It is a simple interface that allows to decouple the event publishing from the event handling. The handler can return an error, which will be returned by the Publish method. The publisher can publish as fire-and-forget, or wait for the handler to confirm the processing (replyHandler).

type EventEnvelope

type EventEnvelope struct {
	Event      Event
	Err        error
	Ctx        context.Context
	Callback   Callback
	ShouldWait bool
}

EventEnvelope is a wrapper around the event that is sent to the bus. It holds other information that is used by the bus to process the event.

func (*EventEnvelope) ProcessOptions

func (e *EventEnvelope) ProcessOptions(options []Option)

ProcessOptions processes the options and sets the values on the envelope.

type EventHandler

type EventHandler func(event Event) error

type EventName

type EventName = string

type Option

type Option func(*EventEnvelope)

func WithAck

func WithAck(callback Callback) Option

WithAck sets the callback function that is called when the event is processed.

func WithWait

func WithWait() Option

WithWait sets the flag that indicates that the event should be processed synchronously.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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