event

package
v0.0.0-...-3ed5f21 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EventBufferSize is the buffer size of the channel for each subscription.
	EventBufferSize = 16
)

Variables

This section is empty.

Functions

func PublishEvent

func PublishEvent(ctx context.Context, events EventService, event interface{})

Types

type Config

type Config struct {
	RedisAddress string
	RedisChannel string
}

type EventService

type EventService interface {
	// Publishes an event to a user's event listeners.
	// If the user is not currently subscribed then this is a no-op.
	PublishEvent(ctx context.Context, event *goapackage.MonitorEvent)

	// Creates a subscription. Caller must call Subscription.Close() when done
	// with the subscription.
	Subscribe(ctx context.Context) (Subscription, error)
}

EventService represents a service for managing event dispatch and event listeners (aka subscriptions).

func NewEventServiceRedis

func NewEventServiceRedis(logger logr.Logger, tp trace.TracerProvider, cfg *Config) (EventService, error)

func NopEventService

func NopEventService() EventService

NopEventService returns an event service that does nothing.

type EventServiceInMemImpl

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

EventServiceInMemImpl represents a service for managing events in the system.

func NewEventServiceInMemImpl

func NewEventServiceInMemImpl() *EventServiceInMemImpl

NewEventServiceInMemImpl returns a new instance of EventService.

func (*EventServiceInMemImpl) PublishEvent

func (s *EventServiceInMemImpl) PublishEvent(ctx context.Context, event *goapackage.MonitorEvent)

PublishEvent publishes event to all of a user's subscriptions.

If user's channel is full then the user is disconnected. This is to prevent slow users from blocking progress.

func (*EventServiceInMemImpl) Subscribe

Subscribe creates a new subscription.

func (*EventServiceInMemImpl) Unsubscribe

func (s *EventServiceInMemImpl) Unsubscribe(sub *SubscriptionInMemImpl)

Unsubscribe disconnects sub from the service.

type EventServiceRedisImpl

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

func (*EventServiceRedisImpl) PublishEvent

func (s *EventServiceRedisImpl) PublishEvent(ctx context.Context, event *goapackage.MonitorEvent)

func (*EventServiceRedisImpl) Subscribe

type Subscription

type Subscription interface {
	// Event stream for all user's event.
	C() <-chan *goapackage.MonitorEvent

	// Closes the event stream channel and disconnects from the event service.
	Close() error
}

Subscription represents a stream of events for a single user.

func NewSubscriptionRedis

func NewSubscriptionRedis(
	ctx context.Context,
	logger logr.Logger,
	c redis.UniversalClient,
	channel string,
) Subscription

type SubscriptionInMemImpl

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

SubscriptionInMemImpl represents a stream of user-related events.

func (*SubscriptionInMemImpl) C

C returns a receive-only channel of user-related events.

func (*SubscriptionInMemImpl) Close

func (s *SubscriptionInMemImpl) Close() error

Close disconnects the subscription from the service it was created from.

type SubscriptionRedisImpl

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

SubscriptionRedisImpl represents a stream of user-related events.

func (*SubscriptionRedisImpl) C

C returns a receive-only channel of user-related events.

func (*SubscriptionRedisImpl) Close

func (s *SubscriptionRedisImpl) Close() error

Close disconnects the subscription from the service it was created from.

Jump to

Keyboard shortcuts

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