eventbus

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: Apache-2.0 Imports: 5 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() event.Bus

New creates and returns a new event.Bus backed by a channel-based implementation. The returned event.Bus allows subscribing to events, publishing events, and managing event subscriptions.

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.

Jump to

Keyboard shortcuts

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