pubsub

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package pubsub provides a pub-sub implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchPublisher

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

BatchPublisher is a publisher that publishes events in batch.

func NewBatchPublisher

func NewBatchPublisher(subs *Subscriptions, window time.Duration) *BatchPublisher

NewBatchPublisher creates a new BatchPublisher instance.

func (*BatchPublisher) Close

func (bp *BatchPublisher) Close()

Close stops the batch publisher

func (*BatchPublisher) Publish

func (bp *BatchPublisher) Publish(event events.DocEvent)

Publish adds the given event to the batch. If the batch is full, it publishes the batch.

type PubSub

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

PubSub is the memory implementation of PubSub, used for single server.

func New

func New() *PubSub

New creates an instance of PubSub.

func (*PubSub) ClientIDs

func (m *PubSub) ClientIDs(docKey types.DocRefKey) []*time.ActorID

ClientIDs returns the clients of the given document.

func (*PubSub) Publish

func (m *PubSub) Publish(
	ctx context.Context,
	publisherID *time.ActorID,
	event events.DocEvent,
)

Publish publishes the given event.

func (*PubSub) Subscribe

func (m *PubSub) Subscribe(
	ctx context.Context,
	subscriber *time.ActorID,
	docKey types.DocRefKey,
) (*Subscription, []*time.ActorID, error)

Subscribe subscribes to the given document keys.

func (*PubSub) Unsubscribe

func (m *PubSub) Unsubscribe(
	ctx context.Context,
	docKey types.DocRefKey,
	sub *Subscription,
)

Unsubscribe unsubscribes the given docKeys.

type Subscription

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

Subscription represents a subscription of a subscriber to documents.

func NewSubscription

func NewSubscription(subscriber *time.ActorID) *Subscription

NewSubscription creates a new instance of Subscription.

func (*Subscription) Close

func (s *Subscription) Close()

Close closes all resources of this Subscription.

func (*Subscription) Events

func (s *Subscription) Events() chan events.DocEvent

Events returns the DocEvent channel of this subscription.

func (*Subscription) ID

func (s *Subscription) ID() string

ID returns the id of this subscription.

func (*Subscription) Publish

func (s *Subscription) Publish(event events.DocEvent) bool

Publish publishes the given event to the subscriber.

func (*Subscription) Subscriber

func (s *Subscription) Subscriber() *time.ActorID

Subscriber returns the subscriber of this subscription.

type Subscriptions

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

Subscriptions is a map of Subscriptions.

func (*Subscriptions) Close

func (s *Subscriptions) Close()

Close closes the subscriptions.

func (*Subscriptions) Delete

func (s *Subscriptions) Delete(id string)

Delete deletes the subscription of the given id.

func (*Subscriptions) Len

func (s *Subscriptions) Len() int

Len returns the length of these subscriptions.

func (*Subscriptions) Publish

func (s *Subscriptions) Publish(event events.DocEvent)

Publish publishes the given event.

func (*Subscriptions) Set

func (s *Subscriptions) Set(sub *Subscription)

Set adds the given subscription.

func (*Subscriptions) Values

func (s *Subscriptions) Values() []*Subscription

Values returns the values of these subscriptions.

Jump to

Keyboard shortcuts

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