eventbus

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Await

func Await[D any](ctx context.Context, bus event.Bus, names ...string) (<-chan event.Of[D], <-chan error, error)

Await returns a channel that receives the first occurrence of an event with one of the specified names from the provided event bus, along with a channel for errors and a possible error. The context is used to cancel the operation if needed. The returned channels should be read from to prevent goroutine leaks.

func New

func New(opts ...Option) event.Bus

New creates a new instance of an event bus with the provided options. The returned event bus is safe for concurrent use and starts processing events immediately. The artificial delay parameter can be set to simulate network latency or other delays.

Types

type Awaiter

type Awaiter[D any] struct {
	// contains filtered or unexported fields
}

Awaiter is a type that provides functionality to wait for specific events from an event.Bus, and then delivers them as typed events via channels. It supports cancellation through the provided context.Context.

func NewAwaiter

func NewAwaiter[D any](bus event.Bus) Awaiter[D]

NewAwaiter creates and returns a new Awaiter instance that uses the provided event.Bus to subscribe and wait for events.

func (Awaiter[D]) Once

func (a Awaiter[D]) Once(ctx context.Context, names ...string) (<-chan event.Of[D], <-chan error, error)

Once listens for the first occurrence of the specified events in the context and returns a channel that emits the event, an error channel, and an error. If no event names are provided, it returns nil channels and no error. The context is used to cancel the operation if necessary.

type Option added in v0.4.5

type Option func(*chanbus)

Option is a type of function that modifies the properties of a [*chanbus] during its initialization. It enables the configuration of various settings of the event bus, such as the artificial delay, before it starts operation. Options are applied in the order they are provided when creating a new event bus through the New function.

func WithArtificialDelay added in v0.4.5

func WithArtificialDelay(delay time.Duration) Option

WithArtificialDelay sets an artificial delay for the event bus. This delay is applied after each event is published to the bus, effectively slowing down the rate of event publishing. The delay duration is specified by the provided time.Duration value. The function returns an Option that can be used to configure a chanbus instance.

Jump to

Keyboard shortcuts

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