Пример #1
0
func NewChaos(name string) *Chaos {
	stop := make(chan bool)
	roll := make(chan bool, 1)
	go func() {
		dice := grid.NewSeededRand()
		delay := time.Duration(30+dice.Intn(600)) * time.Second
		ticker := time.NewTicker(delay)
		happen := ticker.C
		for {
			select {
			case <-stop:
				ticker.Stop()
				return
			case <-happen:
				ticker.Stop()
				delay := time.Duration(30+dice.Intn(600)) * time.Second
				log.Printf("%v: CHAOS", name)
				ticker = time.NewTicker(delay)
				happen = ticker.C
				select {
				case <-stop:
					ticker.Stop()
				case roll <- true:
				}
			}
		}
	}()
	return &Chaos{stop: stop, roll: roll, C: roll}
}
Пример #2
0
func NewDataMaker(minsize, count int) *datamaker {
	dice := grid.NewSeededRand()
	data := make([]string, 1000)
	for i := 0; i < 1000; i++ {
		data[i] = makedata(minsize, dice)
	}

	d := &datamaker{
		count:  count,
		data:   data,
		done:   make(chan bool),
		stop:   make(chan bool),
		output: make(chan string),
	}
	go d.start()

	return d
}
Пример #3
0
func New(name string, n int) Ring {
	return &ring{dice: grid.NewSeededRand(), name: name, n: n}
}