<commit_before>package workers

import (
	"fmt"
	"io/ioutil"
	"log"

	"github.com/AsynkronIT/protoactor-go/actor"
	"github.com/fwatcher/messages"
)

type fileReadActor struct {
	p Producer
}

func newfileReadActor() actor.Actor {
	return &fileReadActor{}
}

//CreateFileReaderProps create and spawn and child here
func CreateFileReaderProps(context actor.Context) *actor.PID {
	fileReadActorProps := actor.FromProducer(newfileReadActor)
	return context.Spawn(fileReadActorProps)
}

func (state *fileReadActor) Receive(context actor.Context) {
	switch msg := context.Message().(type) {

	case *actor.Started:
		state.p = NewProducer()
	case *messages.ReadFile:

		// Need to be sure if this is an okay practice to run a coroutine in an actor
		go func() {
			defer func() {
				if r := recover(); r != nil {
					fmt.Println("goroutine paniced:", r)
				}
			}()
			data := readFile(msg.Filename)
			state.p.Produce(data)
			context.Parent().Tell(&messages.PublishAck{})
		}()<commit_msg>log in place of print<commit_after>package workers

import (
	"fmt"
	"io/ioutil"
	"log"

	"github.com/AsynkronIT/protoactor-go/actor"
	"github.com/fwatcher/messages"
)

type fileReadActor struct {
	p Producer
}

func newfileReadActor() actor.Actor {
	return &fileReadActor{}
}

//CreateFileReaderProps create and spawn and child here
func CreateFileReaderProps(context actor.Context) *actor.PID {
	fileReadActorProps := actor.FromProducer(newfileReadActor)
	return context.Spawn(fileReadActorProps)
}

func (state *fileReadActor) Receive(context actor.Context) {
	switch msg := context.Message().(type) {

	case *actor.Started:
		state.p = NewProducer()
	case *messages.ReadFile:

		// Need to be sure if this is an okay practice to run a coroutine in an actor
		go func() {
			defer func() {
				if r := recover(); r != nil {
					log.Println("goroutine paniced: ", r)
				}
			}()
			data := readFile(msg.Filename)
			state.p.Produce(data)
			context.Parent().Tell(&messages.PublishAck{})
		}()
{'fraction_non_alphanumeric': 0.12708018154311648, 'fraction_numerical': 0.0, 'mean_word_length': 4.166666666666667, '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': '4402000', 'n_tokens_mistral': 730, 'n_tokens_neox': 681, 'n_words': 164}