<commit_before>package client

import (
	"sync"

	"github.com/streadway/amqp"
)

type inflightRegistry struct {
	sync.RWMutex
	requests map[string]chan amqp.Delivery
}

func newInflightRegistry() *inflightRegistry {
	return &inflightRegistry{
		requests: make(map[string]chan amqp.Delivery),
	}
}

func (r *inflightRegistry) add(requestId string) chan amqp.Delivery {
	r.Lock()
	defer r.Unlock()
	ch := make(chan amqp.Delivery, 1)
	r.requests[requestId] = ch
	return ch
}

func (r *inflightRegistry) pop(requestId string) chan amqp.Delivery {
	r.Lock()
	defer r.Unlock()
	if channel, ok := r.requests[requestId]; ok {
		delete(r.requests, requestId)
		return channel
	}
	return nil
}<commit_msg>Godoc for inflight registry<commit_after>package client

import (
	"sync"

	"github.com/streadway/amqp"
)

// inflightRegistry is a registry that keeps track of requests which are currently
// inflight to other services, with a channel back to the originating client
type inflightRegistry struct {
	sync.RWMutex
	requests map[string]chan amqp.Delivery
}

// newInflightRegistry creates an initialised inflight registry
func newInflightRegistry() *inflightRegistry {
	return &inflightRegistry{
		requests: make(map[string]chan amqp.Delivery),
	}
}

// add a request onto the stack
func (r *inflightRegistry) add(requestId string) chan amqp.Delivery {
	r.Lock()
	defer r.Unlock()
	ch := make(chan amqp.Delivery, 1)
	r.requests[requestId] = ch
	return ch
}

// pop a request off the stack
func (r *inflightRegistry) pop(requestId string) chan amqp.Delivery {
	r.Lock()
	defer r.Unlock()
	if channel, ok := r.requests[requestId]; ok {
		delete(r.requests, requestId)
		return channel
	}
	return nil
}
{'fraction_non_alphanumeric': 0.10585452395032525, 'fraction_numerical': 0.0011827321111768185, 'mean_word_length': 4.696969696969697, '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': '3991922', 'n_tokens_mistral': 587, 'n_tokens_neox': 571, 'n_words': 163}