func NewConn(nc net.Conn) *Conn { c := &Conn{ Conn: nc, active: true, subscribers: make(map[chan<- *parser.Message]bool), onclose: make(map[chan<- string]bool), id: user.NextUserID(), } log.Printf("[%s] ** Connected", c.id) return c }
func BenchmarkJoin(b *testing.B) { b.StopTimer() var wg sync.WaitGroup users := make([]string, 10000) chans := make([]string, 100) for i := range users { users[i] = user.NextUserID() if i < len(chans) { chans[i] = "#" + users[i] } } b.StartTimer() for i := 0; i < b.N; i++ { wg.Add(1) go func(i int) { channame := chans[rand.Intn(len(chans))] userid := users[rand.Intn(len(users))] channel, _ := Get(channame, true) channel.Join(userid, "") wg.Done() }(i) } wg.Wait() }