<commit_before>package felixcheck

import (
	"sync"
	"time"

	"github.com/aleasoluciones/goaleasoluciones/scheduledtask"
)

type Event struct {
	Host        string
	Service     string
	State       string
	Metric      interface{}
	Description string
	Tags        []string
	Attributes  map[string]string
	Ttl         float32
}

type CheckEngine struct {
	checkPublishers []CheckPublisher
	results         chan Event
	publishersMutex sync.Mutex
}

func NewCheckEngine() *CheckEngine {
	checkEngine := CheckEngine{[]CheckPublisher{}, make(chan Event), sync.Mutex{}}
	go func() {
		for result := range checkEngine.results {
			checkEngine.publishersMutex.Lock()
			for _, publisher := range checkEngine.checkPublishers {
				go publisher.PublishCheckResult(result)
			}
			checkEngine.publishersMutex.Unlock()
		}
	}()
	return &checkEngine
}

func (ce *CheckEngine) AddResult(event Event) {
	ce.results <- event
}

func (ce *CheckEngine) AddPublisher(publisher CheckPublisher) {
	ce.publishersMutex.Lock()
	ce.checkPublishers = append(ce.checkPublishers, publisher)
	ce.publishersMutex.Unlock()
}

func (ce *CheckEngine) AddCheck(check CheckFunction, period time.Duration) {
	scheduledtask.NewScheduledTask(func() {
		ce.results <- check()
	}, period, 0)
}

func (ce *CheckEngine) AddMultiCheck(check MultiCheckFunction, period time.Duration) {
	scheduledtask.NewScheduledTask(func() {
		for _, result := range check() {
			ce.results <- result
		}
	}, period, 0)
}<commit_msg>Not all the publisher support concurrent use<commit_after>package felixcheck

import (
	"sync"
	"time"

	"github.com/aleasoluciones/goaleasoluciones/scheduledtask"
)

type Event struct {
	Host        string
	Service     string
	State       string
	Metric      interface{}
	Description string
	Tags        []string
	Attributes  map[string]string
	Ttl         float32
}

type CheckEngine struct {
	checkPublishers []CheckPublisher
	results         chan Event
	publishersMutex sync.Mutex
}

func NewCheckEngine() *CheckEngine {
	checkEngine := CheckEngine{[]CheckPublisher{}, make(chan Event), sync.Mutex{}}
	go func() {
		for result := range checkEngine.results {
			checkEngine.publishersMutex.Lock()
			for _, publisher := range checkEngine.checkPublishers {
				publisher.PublishCheckResult(result)
			}
			checkEngine.publishersMutex.Unlock()
		}
	}()
	return &checkEngine
}

func (ce *CheckEngine) AddResult(event Event) {
	ce.results <- event
}

func (ce *CheckEngine) AddPublisher(publisher CheckPublisher) {
	ce.publishersMutex.Lock()
	ce.checkPublishers = append(ce.checkPublishers, publisher)
	ce.publishersMutex.Unlock()
}

func (ce *CheckEngine) AddCheck(check CheckFunction, period time.Duration) {
	scheduledtask.NewScheduledTask(func() {
		ce.results <- check()
	}, period, 0)
}

func (ce *CheckEngine) AddMultiCheck(check MultiCheckFunction, period time.Duration) {
	scheduledtask.NewScheduledTask(func() {
		for _, result := range check() {
			ce.results <- result
		}
	}, period, 0)
}
{'fraction_non_alphanumeric': 0.10699865410497982, 'fraction_numerical': 0.0026917900403768506, 'mean_word_length': 4.252650176678445, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1298932', 'n_tokens_mistral': 998, 'n_tokens_neox': 933, 'n_words': 213}