Documentation ¶
Overview ¶
Package sync provides the synchronization primitives for the server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyLocked = errors.New("already locked")
ErrAlreadyLocked is returned when the lock is already locked.
Functions ¶
This section is empty.
Types ¶
type Coordinator ¶
type Coordinator interface { // NewLocker creates a sync.Locker. NewLocker(ctx context.Context, key Key) (Locker, error) // Subscribe subscribes to the given documents. Subscribe( ctx context.Context, subscriber *time.ActorID, documentID types.ID, ) (*Subscription, []*time.ActorID, error) // Unsubscribe unsubscribes from the given documents. Unsubscribe( ctx context.Context, documentID types.ID, sub *Subscription, ) error // Publish publishes the given event. Publish(ctx context.Context, publisherID *time.ActorID, event DocEvent) // Members returns the members of this cluster. Members() map[string]*ServerInfo // Close closes all resources of this Coordinator. Close() error }
Coordinator provides synchronization functions such as locks and event Pub/Sub.
type DocEvent ¶
type DocEvent struct { Type types.DocEventType Publisher *time.ActorID DocumentID types.ID Body types.DocEventBody }
DocEvent represents events that occur related to the document.
type Locker ¶
type Locker interface { // Lock locks the mutex with a cancelable context Lock(ctx context.Context) error // TryLock locks the mutex if not already locked by another session. TryLock(ctx context.Context) error // Unlock unlocks the mutex. Unlock(ctx context.Context) error }
A Locker represents an object that can be locked and unlocked.
type ServerInfo ¶
type ServerInfo struct { ID string `json:"id"` Hostname string `json:"hostname"` UpdatedAt gotime.Time `json:"updated_at"` }
ServerInfo represents the information of the Server.
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 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) Subscriber ¶
func (s *Subscription) Subscriber() *time.ActorID
Subscriber returns the subscriber of this subscription.