Skip to content

Commit

Permalink
add a customer filter to find session (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
beatless authored Nov 16, 2023
1 parent 1698d2e commit 5466440
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ func NewGroup(n string) *Group {
}
}

// FindMember Find a member with customer filter
func (c *Group) FindMember(filter func(ses *session.Session) bool) (*session.Session, error) {
c.mu.RLock()
defer c.mu.RUnlock()

for _, s := range c.sessions {
if filter(s) {
return s, nil
}
}

return nil, ErrMemberNotFound
}

// Member returns specified UID's session
func (c *Group) Member(uid int64) (*session.Session, error) {
c.mu.RLock()
Expand Down

0 comments on commit 5466440

Please sign in to comment.