<commit_before>package paxos

type instance struct {
	vin     chan string
	v       string
	done    chan int
	ins     chan Packet
	cPutter putCloser // Coordinator
}

type clusterer interface {
	cluster(seqn uint64) *cluster
}

func newInstance(seqn uint64, cf clusterer) *instance {
	cIns, aIns, lIns := make(ChanPutCloser), make(ChanPutCloser), make(ChanPutCloser)
	sIns := make(ChanPutCloser)
	ins := &instance{
		vin:     make(chan string),
		done:    make(chan int),
		ins:     make(chan Packet),
		cPutter: cIns,
	}

	go func() {
		cx := cf.cluster(seqn)

		ch := make(chan string)
		go coordinator(cIns, cx, cx)
		go acceptor(aIns, cx)
		go func() {
			ch <- learner(uint64(cx.Quorum()), lIns)
		}()
		go func() {
			ch <- sink(sIns)
		}()

		for {
			select {
			case p := <-ins.ins:
				if closed(ins.ins) {
					ins.cPutter.Close()
					aIns.Close()
					lIns.Close()
					sIns.Close()
					return
				}
				p.SetFrom(cx.indexByAddr(p.Addr))
				cIns.Put(p.Msg)
				aIns.Put(p.Msg)
				lIns.Put(p.Msg)
				sIns.Put(p.Msg)
			case v := <-ch:
				ins.v = v
				close(ch)
				close(ins.done)
				cx.Put(newLearn(ins.v))
				return
			}
		}
	}()

	return ins
}

func (it *instance) PutFrom(addr string, m Msg) {
	go func() {
		it.ins <- Packet{m, addr}
	}()
}

func (ins *instance) Value() string {
	<-ins.done
	return ins.v
}

func (ins *instance) Close() {
	close(ins.ins)
}

func (ins *instance) Propose(v string) {
	ins.cPutter.Put(newPropose(v))
}<commit_msg>refactor<commit_after>package paxos

type instance struct {
	vin     chan string
	v       string
	done    chan int
	ins     chan Packet
	cPutter putCloser // Coordinator
}

type clusterer interface {
	cluster(seqn uint64) *cluster
}

func newInstance(seqn uint64, cf clusterer) *instance {
	cIns, aIns, lIns := make(ChanPutCloser), make(ChanPutCloser), make(ChanPutCloser)
	sIns := make(ChanPutCloser)
	ins := &instance{
		vin:     make(chan string),
		done:    make(chan int),
		ins:     make(chan Packet),
		cPutter: cIns,
	}

	go func() {
		cx := cf.cluster(seqn)

		ch := make(chan string)
		go coordinator(cIns, cx, cx)
		go acceptor(aIns, cx)
		go func() {
			ch <- learner(uint64(cx.Quorum()), lIns)
		}()
		go func() {
			ch <- sink(sIns)
		}()

		for {
			select {
			case p := <-ins.ins:
				if closed(ins.ins) {
					ins.cPutter.Close()
					aIns.Close()
					lIns.Close()
					sIns.Close()
					return
				}
				p.SetFrom(cx.indexByAddr(p.Addr))
				cIns.Put(p.Msg)
				aIns.Put(p.Msg)
				lIns.Put(p.Msg)
				sIns.Put(p.Msg)
			case v := <-ch:
				ins.v = v
				close(ch)
				close(ins.done)
				cx.Put(newLearn(ins.v))
				return
			}
		}
	}()

	return ins
}

func (it *instance) PutFrom(addr string, m Msg) {
	go func() {
		it.ins <- Packet{m, addr}
	}()
}

func (ins *instance) Value() string {
	<-ins.done
	return ins.v
}

func (ins *instance) Close() {
	close(ins.ins)
}

func (ins *instance) Propose(v string) {
	// The from address doesn't matter.
	ins.PutFrom("", newPropose(v))
}
{'fraction_non_alphanumeric': 0.15286195286195287, 'fraction_numerical': 0.00404040404040404, 'mean_word_length': 2.746532156368222, 'pattern_counts': {'":': 0, '<': 15, '<?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': '6161966', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1192, 'n_words': 274}