<commit_before>package zutil

import (
	"sync"
	"net"
)

type nonblockingSendChannel struct {
	in chan net.IP
	out chan net.IP
	queue UnboundedQueue
	cond *sync.Cond
	done bool
}

func addToQueue(nbsc *nonblockingSendChannel) {
	for elt := range nbsc.in {
		nbsc.cond.L.Lock()
		nbsc.queue.Push(elt)
		nbsc.cond.Signal()
		nbsc.cond.L.Unlock()
	}
	nbsc.cond.L.Lock()
	nbsc.done = true
	nbsc.cond.Signal()
	nbsc.cond.L.Unlock()
}

func sendToChannel(nbsc *nonblockingSendChannel) {
	for !nbsc.done {
		nbsc.cond.L.Lock()
		for !(nbsc.queue.Size() > 0) && !nbsc.done {
			nbsc.cond.Wait()
		}
		if (nbsc.done) {
			nbsc.cond.L.Unlock()
		} else {
			elt := nbsc.queue.Pop()
			nbsc.cond.L.Unlock()
			nbsc.out <- elt
		}
	}
	for nbsc.queue.Size() > 0 {
		nbsc.out <- nbsc.queue.Pop()
	}
	close(nbsc.out)
}

func NewNonblockingSendPair() (chan net.IP, chan net.IP) {
	nbsc := nonblockingSendChannel{in: make(chan net.IP, 1000), 
		out: make(chan net.IP, 1000), 
		queue: NewUnboundedRing(1000),
		cond: sync.NewCond(new(sync.Mutex))}
	go addToQueue(&nbsc)<commit_msg>Change wait condition to make more sense<commit_after>package zutil

import (
	"sync"
	"net"
)

type nonblockingSendChannel struct {
	in chan net.IP
	out chan net.IP
	queue UnboundedQueue
	cond *sync.Cond
	done bool
}

func addToQueue(nbsc *nonblockingSendChannel) {
	for elt := range nbsc.in {
		nbsc.cond.L.Lock()
		nbsc.queue.Push(elt)
		nbsc.cond.Signal()
		nbsc.cond.L.Unlock()
	}
	nbsc.cond.L.Lock()
	nbsc.done = true
	nbsc.cond.Signal()
	nbsc.cond.L.Unlock()
}

func sendToChannel(nbsc *nonblockingSendChannel) {
	for !nbsc.done {
		nbsc.cond.L.Lock()
		for !(nbsc.queue.Size() > 0 || nbsc.done) {
			nbsc.cond.Wait()
		}
		if (nbsc.done) {
			nbsc.cond.L.Unlock()
		} else {
			elt := nbsc.queue.Pop()
			nbsc.cond.L.Unlock()
			nbsc.out <- elt
		}
	}
	for nbsc.queue.Size() > 0 {
		nbsc.out <- nbsc.queue.Pop()
	}
	close(nbsc.out)
}

func NewNonblockingSendPair() (chan net.IP, chan net.IP) {
	nbsc := nonblockingSendChannel{in: make(chan net.IP, 1000), 
		out: make(chan net.IP, 1000), 
		queue: NewUnboundedRing(1000),
		cond: sync.NewCond(new(sync.Mutex))}
	go addToQueue(&nbsc)
{'fraction_non_alphanumeric': 0.15923862581244197, 'fraction_numerical': 0.012999071494893221, 'mean_word_length': 3.461697722567288, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '502995', 'n_tokens_mistral': 1015, 'n_tokens_neox': 913, 'n_words': 171}