Documentation
¶
Overview ¶
Package event provides a small pub/sub store for intercepting events and waiting for a specific one to arrive.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAwaitTimeout = errors.New("await timeout")
Functions ¶
This section is empty.
Types ¶
type Awaiter ¶
type Awaiter[T any] interface { // Match reports whether the event satisfies the awaiter, in which case the // store drops it. Match(event T) bool }
Awaiter waits for a specific event.
type EventAwaiter ¶
type EventAwaiter[T, Z any] struct { // contains filtered or unexported fields }
EventAwaiter waits for an event of type T that matches a condition.
func NewEventAwaiter ¶
func NewEventAwaiter[T, Z any](s *Store[Z], match func(T) bool) *EventAwaiter[T, Z]
NewEventAwaiter creates and registers a new EventAwaiter.
func (*EventAwaiter[T, Z]) Await ¶
func (e *EventAwaiter[T, Z]) Await(deadline time.Duration) (T, error)
Await waits for a matching event or for the deadline to expire.
func (*EventAwaiter[T, Z]) Close ¶
func (e *EventAwaiter[T, Z]) Close()
func (*EventAwaiter[T, Z]) Match ¶
func (e *EventAwaiter[T, Z]) Match(event Z) bool
Match delivers the event to the waiting caller if it matches.
type Store ¶
type Store[T any] struct { // contains filtered or unexported fields }
Store manages a collection of interceptors and awaiters for events of type T.
func (*Store[T]) AddAwaiter ¶
AddAwaiter adds an awaiter to the store.
func (*Store[T]) AddInterceptor ¶
func (s *Store[T]) AddInterceptor(f func(T)) RemoveHandler
AddInterceptor adds an interceptor to the store and returns the function that removes it again.
Removal is by the returned handle rather than by the callback value, because func values cannot be compared: every closure produced by one func literal shares that literal's code pointer, so the handlers HandleEvent registers are indistinguishable from each other.