rmgr

package
v0.0.0-...-551f129 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const World = ""

World is the default room (identity) where a new session starts

Variables

View Source
var (
	ErrBadInput = errors.New("bad input parameter")
	ErrExisted  = errors.New("already existed")
	ErrNotFound = errors.New("not found")
	ErrRoomDrop = errors.New("room is dropping")
)

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Bucket is a shard of session holder

func NewBucket

func NewBucket() *Bucket

func (*Bucket) DelSession

func (b *Bucket) DelSession(uid string)

func (*Bucket) Enumerate

func (b *Bucket) Enumerate(accept func(*Session))

func (*Bucket) FindRoom

func (b *Bucket) FindRoom(rid string) *Room

func (*Bucket) FindSession

func (b *Bucket) FindSession(uid string) *Session

func (*Bucket) JoinRoom

func (b *Bucket) JoinRoom(uid, rid string) (orid string, err error)

JoinRoom join the user's session (uid) to the room (rid), returns the original room (orid)

func (*Bucket) Put

func (b *Bucket) Put(ses *Session) (*Session, error)

Put a session into the bucket, returns the last session. The bucket could be in an inconsistent state when error happens, to ensure a session is always removed from bucket when it is not needed, do as below:

_, err := bucket.Put(rmgr.NewSession(uid))
defer bucket.DelSession(uid)
if err != nil { /* handle error and quit */ }

func (*Bucket) RoomsSnapshot

func (b *Bucket) RoomsSnapshot() []*Room

func (*Bucket) SessionsSnapshot

func (b *Bucket) SessionsSnapshot() []*Session

type Room

type Room struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Room is a (virtual) place where session gathers

func (*Room) Enumerate

func (r *Room) Enumerate(accept func(*Session))

func (*Room) RID

func (r *Room) RID() string

func (*Room) SessionsSnapshot

func (r *Room) SessionsSnapshot() []*Session

type Session

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

Session is a user's session

func NewSession

func NewSession(uid, rid string, cancel context.CancelFunc) *Session

func (*Session) Birth

func (s *Session) Birth() string

func (*Session) Close

func (s *Session) Close()

func (*Session) RID

func (s *Session) RID() string

func (*Session) UID

func (s *Session) UID() string

Jump to

Keyboard shortcuts

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