<commit_before>package service

import (
	"sync"
)

type Dispatcher struct {
	active    map[string]bool
	rwm       *sync.RWMutex
	handler   Handler
	semaphore chan int
}

func (d *Dispatcher) Handle(filePath string) {
	d.semaphore <- 1
	d.rwm.RLock()
	_, found := d.active[filePath]
	d.rwm.RUnlock()
	if !found {
		go func() {
			d.rwm.Lock()
			d.active[filePath] = true
			d.rwm.Unlock()

			d.handler.Handle(filePath)

			d.rwm.Lock()
			delete(d.active, filePath)
			d.rwm.Unlock()
			<-d.semaphore
		}()
	}
}

func NewDispatcher(handler Handler, size int) *Dispatcher {
	return &Dispatcher{make(map[string]bool), &sync.RWMutex{}, handler, make(chan int, size)}
}<commit_msg>refactor semaphore chan type<commit_after>package service

import (
	"sync"
)

type Dispatcher struct {
	active    map[string]bool
	rwm       *sync.RWMutex
	handler   Handler
	semaphore chan bool
}

func (d *Dispatcher) Handle(filePath string) {
	d.semaphore <- true
	d.rwm.RLock()
	_, found := d.active[filePath]
	d.rwm.RUnlock()
	if !found {
		go func() {
			d.rwm.Lock()
			d.active[filePath] = true
			d.rwm.Unlock()

			d.handler.Handle(filePath)

			d.rwm.Lock()
			delete(d.active, filePath)
			d.rwm.Unlock()
			<-d.semaphore
		}()
	}
}

func NewDispatcher(handler Handler, size int) *Dispatcher {
	return &Dispatcher{make(map[string]bool), &sync.RWMutex{}, handler, make(chan bool, size)}
}
{'fraction_non_alphanumeric': 0.14513788098693758, 'fraction_numerical': 0.000725689404934688, 'mean_word_length': 3.566225165562914, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3910302', 'n_tokens_mistral': 597, 'n_tokens_neox': 541, 'n_words': 111}