Chatroom 2 (#10)
* Remove unused method. Don't panic if unknown room. * Need a Connected() check for rooms publishing - don't do the work of rendering for a dead connection * Make vars private. * Linter issues * Remove Connected() * Mutation observer. Publish 4x / second. --------- Co-authored-by: João Gonçalves <joao.goncalves01@gmail.com>
This commit is contained in:
@@ -94,7 +94,7 @@ func (r *Room[TR, TU]) Publish() {
|
||||
}
|
||||
}
|
||||
|
||||
// Get room data. This is a copy.
|
||||
// GetData returns a copy of room data.
|
||||
// Accepts an optional subset function to transform data before copying.
|
||||
func (r *Room[TR, TU]) GetData(subsetFn ...func(*TR) TR) TR {
|
||||
r.dataMu.RLock()
|
||||
@@ -116,12 +116,6 @@ func (r *Room[TR, TU]) Leave(u *TU) {
|
||||
r.leave <- u
|
||||
}
|
||||
|
||||
func (r *Room[TR, TU]) MemberCount() int {
|
||||
r.membersMu.RLock()
|
||||
defer r.membersMu.RUnlock()
|
||||
return len(r.members)
|
||||
}
|
||||
|
||||
func NewRoom[TR any, TU comparable](n string) *Room[TR, TU] {
|
||||
return &Room[TR, TU]{
|
||||
Name: n,
|
||||
@@ -135,7 +129,7 @@ func NewRoom[TR any, TU comparable](n string) *Room[TR, TU] {
|
||||
|
||||
func (r *Room[TR, TU]) run() {
|
||||
defer close(r.done)
|
||||
publishTicker := time.NewTicker(400 * time.Millisecond)
|
||||
publishTicker := time.NewTicker(250 * time.Millisecond)
|
||||
defer publishTicker.Stop()
|
||||
for {
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user