event

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const EventBufferSize = 16

EventBufferSize is the size of the event buffer of the channel for each subscribers.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type    EventType `json:"type"`
	Message string    `json:"message"`
	Payload any       `json:"payload"`
}

Event is the event that is published to the subscription.

type EventService

type EventService struct {
	// contains filtered or unexported fields
}

EventService is a service for publishing and subscribing to events.

func NewEventService

func NewEventService() *EventService

NewEventService creates a new event service.

func (*EventService) PublishEvent

func (s *EventService) PublishEvent(ctx context.Context, event Event)

PublishEvent publishes the given event to all subscribers.

func (*EventService) Subscribe

func (s *EventService) Subscribe(ctx context.Context, event EventType) (sub *Subscription)

Subscribe subscribes to the given event. Context is used to automatically unsubscribe the subscription when it is canceled.

func (*EventService) Unsubscribe

func (s *EventService) Unsubscribe(sub *Subscription)

Unsubscribe unsubscribes the given subscription. It is safe to call this method concurrently.

type EventType

type EventType string

EventType is the type of the event.

const (
	EngineShouldResumeEvent EventType = "engineShouldResume"
	EngineShouldPauseEvent  EventType = "engineShouldPause"
)

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

Subscription is a subscription to an event service.

func (*Subscription) C

func (s *Subscription) C() <-chan Event

C returns the channel of the subscription.

func (*Subscription) Close

func (s *Subscription) Close()

Close unsubscribes the subscription.

func (*Subscription) Ctx

func (s *Subscription) Ctx() context.Context

Ctx returns the context of the subscription.

Jump to

Keyboard shortcuts

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