<commit_before>package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"net"
	"time"
)

type client struct {
	Chan chan<- string
	Name string
}

var (
	entering = make(chan client)
	leaving  = make(chan client)
	messages = make(chan string)
	timeout  time.Duration
)

func broadcaster() {
	var online int
	clients := make(map[client]bool)
	for {
		select {
		case msg := <-messages:
			for cln := range clients {
				select {
				case cln.Chan <- "\t" + msg:
				default: // skip slow client
				}
			}
		case cln := <-entering:
			clients[cln] = true
			online++
			cln.Chan <- fmt.Sprintf("Online: %d", online)
			for c := range clients {
				cln.Chan <- "[ " + c.Name + " ]"
			}
		case cln := <-leaving:
			online--
			delete(clients, cln)
			close(cln.Chan)
		}
	}
}

func handleConn(conn net.Conn) {
	rch := make(chan string)
	wch := make(chan string, 10)<commit_msg>[8.14] add async cleint join notification<commit_after>package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"net"
	"time"
)

type client struct {
	Chan chan<- string
	Name string
}

var (
	entering = make(chan client)
	leaving  = make(chan client)
	messages = make(chan string)
	semafore = make(chan struct{}, 5)
	timeout  time.Duration
)

func broadcaster() {
	var online int
	clients := make(map[client]bool)
	for {
		select {
		case msg := <-messages:
			for cln := range clients {
				select {
				case cln.Chan <- "\t" + msg:
				default: // skip slow client
				}
			}
		case cln := <-entering:
			clients[cln] = true
			online++
			go func() { // FIXME: need QA this
				semafore <- struct{}{}
				cln.Chan <- fmt.Sprintf("Online: %d", online)
				for c := range clients {
					cln.Chan <- "[ " + c.Name + " ]"
				}
				<-semafore
			}()
		case cln := <-leaving:
			online--
			delete(clients, cln)
			close(cln.Chan)
		}
	}
}

func handleConn(conn net.Conn) {
	rch := make(chan string)
	wch := make(chan string, 10)
{'fraction_non_alphanumeric': 0.15279241306638566, 'fraction_numerical': 0.004214963119072708, 'mean_word_length': 2.6945525291828796, 'pattern_counts': {'":': 0, '<': 19, '<?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': '5249209', 'n_tokens_mistral': 858, 'n_tokens_neox': 722, 'n_words': 191}