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.
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 ¶
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
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.