<commit_before>package sup_test

import (
	"fmt"
	"time"

	"."
)

func ExampleDaemonSpawner() {
	type bigTask string

	var workerFactory = func(task bigTask) sup.Agent {
		return func(super sup.Supervisor) {
			// has lots to do, i'm sure
			time.Sleep(time.Millisecond * 100)
		}
	}

	firehose := make(chan bigTask)
	cntWorkFound := 0
	var workFinder sup.Agent = sup.Looper(func(super sup.Supervisor) {
		select {
		case firehose <- "work":
			cntWorkFound++
			if cntWorkFound >= 12 {
				close(firehose)
				panic(nil)
			}
		case <-super.QuitCh():
			return
		}
	})

	var daemonMaster sup.Agent = func(super sup.Supervisor) {
		mgr := sup.NewManager(super)
		for {
			select {
			case <-super.QuitCh():
				goto procede
			case todo, ok := <-firehose:
				if !ok {
					goto procede
				}
				taskName := string(todo)
				go mgr.NewTask(taskName).Run(workerFactory(todo))
			}
			// do i need to 'step' periodically here?  how important is manager state maint?
			// or check if it has any errors to raise, even if we're not done accepting?  yes that's important.
		}
	procede:
		fmt.Printf("daemonMaster wrapping up\n")
		defer fmt.Printf("daemonMaster returned\n")
		mgr.Work()
	}

	rootWrit := sup.NewWrit()
	rootWrit.Run(func(super sup.Supervisor) {
		mgr := sup.NewManager(super)
		go mgr.NewTask("workFinder").Run(workFinder)
		go mgr.NewTask("daemonMaster").Run(daemonMaster)
		mgr.Work()
	})

	// Output:
	// daemonMaster wrapping up
	// daemonMaster returned
}
<commit_msg>Unique names to writs in daemonspawner example.<commit_after>package sup_test

import (
	"fmt"
	"time"

	"."
)

func ExampleDaemonSpawner() {
	type bigTask string

	var workerFactory = func(task bigTask) sup.Agent {
		return func(super sup.Supervisor) {
			// has lots to do, i'm sure
			time.Sleep(time.Millisecond * 100)
		}
	}

	firehose := make(chan bigTask)
	cntWorkFound := 0
	var workFinder sup.Agent = sup.Looper(func(super sup.Supervisor) {
		select {
		case firehose <- bigTask(fmt.Sprintf("work-%02d", cntWorkFound)):
			cntWorkFound++
			if cntWorkFound >= 12 {
				close(firehose)
				panic(nil)
			}
		case <-super.QuitCh():
			return
		}
	})

	var daemonMaster sup.Agent = func(super sup.Supervisor) {
		mgr := sup.NewManager(super)
		for {
			select {
			case <-super.QuitCh():
				goto procede
			case todo, ok := <-firehose:
				if !ok {
					goto procede
				}
				taskName := string(todo)
				go mgr.NewTask(taskName).Run(workerFactory(todo))
			}
			// do i need to 'step' periodically here?  how important is manager state maint?
			// or check if it has any errors to raise, even if we're not done accepting?  yes that's important.
		}
	procede:
		fmt.Printf("daemonMaster wrapping up\n")
		defer fmt.Printf("daemonMaster returned\n")
		mgr.Work()
	}

	rootWrit := sup.NewWrit()
	rootWrit.Run(func(super sup.Supervisor) {
		mgr := sup.NewManager(super)
		go mgr.NewTask("workFinder").Run(workFinder)
		go mgr.NewTask("daemonMaster").Run(daemonMaster)
		mgr.Work()
	})

	// Output:
	// daemonMaster wrapping up
	// daemonMaster returned
}

{'fraction_non_alphanumeric': 0.12832294059730884, 'fraction_numerical': 0.004594683295044306, 'mean_word_length': 3.2869198312236287, 'pattern_counts': {'":': 1, '<': 11, '<?xml version=': 0, '>': 5, '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': '943896', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1096, 'n_words': 267}