Make Ring.NewConsumer seq argument mandatory

There's no point in supporting a nil argument anymore.
This commit is contained in:
Simon Ser 2020-04-07 14:45:08 +02:00
parent 7ce369958e
commit dd08acc3ea
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 9 additions and 21 deletions

View File

@ -661,15 +661,12 @@ func (dc *downstreamConn) welcome() error {
})
dc.forEachNetwork(func(net *network) {
var seqPtr *uint64
if sendHistory {
seq, ok := net.history[dc.clientName]
if ok {
seqPtr = &seq
}
if !sendHistory || !ok {
return
}
consumer := net.ring.NewConsumer(seqPtr)
consumer := net.ring.NewConsumer(seq)
// TODO: this means all history is lost when trying to send it while the
// upstream is disconnected. We need to store history differently so that

19
ring.go
View File

@ -31,27 +31,18 @@ func (r *Ring) Produce(msg *irc.Message) {
r.cur++
}
// Cur returns the current history sequence number.
func (r *Ring) Cur() uint64 {
return r.cur
}
// NewConsumer creates a new ring buffer consumer.
//
// If seq is nil, the consumer will get messages starting from the last
// producer message. If seq is non-nil, the consumer will get messages starting
// from the specified history sequence number (see RingConsumer.Close).
//
// The consumer can only be used from a single goroutine.
func (r *Ring) NewConsumer(seq *uint64) *RingConsumer {
consumer := &RingConsumer{ring: r}
if seq != nil {
consumer.cur = *seq
} else {
consumer.cur = r.cur
}
// The consumer will get messages starting from the specified history sequence
// number (see Ring.Cur).
func (r *Ring) NewConsumer(seq uint64) *RingConsumer {
consumer := &RingConsumer{ring: r, cur: seq}
r.consumers = append(r.consumers, consumer)
return consumer
}