From dd08acc3ea2e2fc1d3a29c00c106166ba24c73ab Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 7 Apr 2020 14:45:08 +0200 Subject: [PATCH] Make Ring.NewConsumer seq argument mandatory There's no point in supporting a nil argument anymore. --- downstream.go | 11 ++++------- ring.go | 19 +++++-------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/downstream.go b/downstream.go index fd53bac..0dcd2b7 100644 --- a/downstream.go +++ b/downstream.go @@ -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 - } + seq, ok := net.history[dc.clientName] + 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 diff --git a/ring.go b/ring.go index 0e874c6..50714e1 100644 --- a/ring.go +++ b/ring.go @@ -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 }