extension

package
v3.1.0-beta2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 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 AsyncEventBroker

type AsyncEventBroker[E any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

AsyncEventBroker maintains a list of listeners interested in a specific type of event. Events are sent in parallel to all listeners, and no result is returned.

func (*AsyncEventBroker[E]) AddListener

func (eb *AsyncEventBroker[E]) AddListener(name string, listener func(E))

AddListener registers the named listener, replacing one with a duplicate name if present. Listeners should be added in order of priority, most significant first.

func (*AsyncEventBroker[E]) AsyncTestListener

func (eb *AsyncEventBroker[E]) AsyncTestListener(name string, capacity int) func() (*E, error)

AsyncTestListener returns a func that will wait for an event and return it, or timeout with an error.

func (*AsyncEventBroker[E]) Emit

func (eb *AsyncEventBroker[E]) Emit(event *E)

Emit sends the provided event to each registered listener in parallel.

func (*AsyncEventBroker[E]) RemoveListener

func (eb *AsyncEventBroker[E]) RemoveListener(name string)

RemoveListener unregisters the named listener.

type EventBroker

type EventBroker[E any, R interface{}] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

EventBroker maintains a list of listeners interested in a specific type of event.

func (*EventBroker[E, R]) AddListener

func (eb *EventBroker[E, R]) AddListener(name string, listener func(E) *R)

AddListener registers the named listener, replacing one with a duplicate name if present. Listeners should be added in order of priority, most significant first.

func (*EventBroker[E, R]) Emit

func (eb *EventBroker[E, R]) Emit(event *E) *R

Emit sends the provided event to each registered listener in order, until one returns a non-nil result. That result will be returned to the caller.

func (*EventBroker[E, R]) RemoveListener

func (eb *EventBroker[E, R]) RemoveListener(name string)

RemoveListener unregisters the named listener.

type Events

type Events struct {
	AfterMessageDeleted AsyncEventBroker[event.MessageMetadata]
	AfterMessageStored  AsyncEventBroker[event.MessageMetadata]
	BeforeMailAccepted  EventBroker[event.AddressParts, bool]
	BeforeMessageStored EventBroker[event.InboundMessage, event.InboundMessage]
}

Events defines all the event types supported by the extension host.

Before-events provide an opportunity for extensions to alter how Inbucket responds to that type of event. These events are processed synchronously; expensive operations will reduce the perceived performance of Inbucket. The first listener in the list to respond with a non-nil value will determine the response, and the remaining listeners will not be called.

After-events allow extensions to take an action after an event has completed. These events are processed asynchronously with respect to the rest of Inbuckets operation. However, an event listener will not be called until the one before it complets.

type Host

type Host struct {
	Events *Events
}

Host defines extension points for Inbucket.

func NewHost

func NewHost() *Host

NewHost creates a new extension host.

type Void

type Void struct{}

Void indicates the event emitter will ignore any value returned by listeners.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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