<commit_before>package goio

import (
	"sync"
)

type Users struct {
	Map  map[string]*User
	lock sync.RWMutex
}

func (self *Users) Count() int {
	self.lock.Lock()
	defer self.lock.Unlock()

	return len(self.Map)
}

func (self *Users) Add(user *User) {
	if nil != self.Get(user.Id) {
		return
	}

	self.lock.Lock()
	defer self.lock.Unlock()
	user.On("destroy", func(message *Message) {
		self.Delete(user.Id)
	})

	self.Map[user.Id] = user
}

func (self *Users) Delete(userId string) {
	self.lock.Lock()
	defer self.lock.Unlock()

	delete(self.Map, userId)
}

func (self *Users) Get(userId string) *User {<commit_msg>fix the lock<commit_after>package goio

import (
	"sync"
)

type Users struct {
	Map  map[string]*User
	lock sync.RWMutex
}

func (self *Users) Receive(message *Message) {
	self.lock.Lock()
	defer self.lock.Unlock()

	for _, user := range self.Map {
		if user != nil {
			user.Receive(message)
		}
	}
}

func (self *Users) Count() int {
	self.lock.Lock()
	defer self.lock.Unlock()

	return len(self.Map)
}

func (self *Users) Add(user *User) {
	if nil != self.Get(user.Id) {
		return
	}

	user.On("destroy", func(message *Message) {
		self.Delete(user.Id)
	})

	self.Receive(&Message{
		EventName: "join",
		CallerId:  user.Id,
	})

	self.lock.Lock()
	self.Map[user.Id] = user
	self.lock.Unlock()
}

func (self *Users) Delete(userId string) {
	self.lock.Lock()
	defer self.lock.Unlock()

	delete(self.Map, userId)

	// send global message to all members
	self.Receive(&Message{
		EventName: "leave",
		CallerId:  userId,
	})
}

func (self *Users) Get(userId string) *User {
{'fraction_non_alphanumeric': 0.16216216216216217, 'fraction_numerical': 0.0, 'mean_word_length': 3.7522388059701495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3238014', 'n_tokens_mistral': 640, 'n_tokens_neox': 624, 'n_words': 143}