deliveries is non buffered channel. When you want consume messages in go routine ,it waits for go routine to end. Would not be nice to use buffered channel here?
func (ch *Channel) Consume(queue, consumer string, autoAck, exclusive, noLocal, noWait bool, args Table) (<-chan Delivery, error) {
// When we return from ch.call, there may be a delivery already for the
// consumer that hasn't been added to the consumer hash yet. Because of
// this, we never rely on the server picking a consumer tag for us.
if err := args.Validate(); err != nil {
return nil, err
}
if consumer == "" {
consumer = uniqueConsumerTag()
}
req := &basicConsume{
Queue: queue,
ConsumerTag: consumer,
NoLocal: noLocal,
NoAck: autoAck,
Exclusive: exclusive,
NoWait: noWait,
Arguments: args,
}
res := &basicConsumeOk{}
deliveries := make(chan Delivery)
//Suggestion is
deliveries := make(chan Delivery,10)
ch.consumers.add(consumer, deliveries)
if err := ch.call(req, res); err != nil {
ch.consumers.cancel(consumer)
return nil, err
}
return (<-chan Delivery)(deliveries), nil
}
In fact ch.consumers.add implement an infinite buffered channel (which could be an issue on its own: #489 )
So adding a buffer here would not change anything.
deliveries is non buffered channel. When you want consume messages in go routine ,it waits for go routine to end. Would not be nice to use buffered channel here?