Documentation
¶
Overview ¶
Package pubsub provides a pub-sub implementation.
Index ¶
- type BatchPublisher
- type PubSub
- func (m *PubSub) ClientIDs(docKey types.DocRefKey) []*time.ActorID
- func (m *PubSub) Publish(ctx context.Context, publisherID *time.ActorID, event events.DocEvent)
- func (m *PubSub) Subscribe(ctx context.Context, subscriber *time.ActorID, docKey types.DocRefKey) (*Subscription, []*time.ActorID, error)
- func (m *PubSub) Unsubscribe(ctx context.Context, docKey types.DocRefKey, sub *Subscription)
- type Subscription
- type Subscriptions
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) 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 (*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 ¶
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) 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.