From d6dfe83ebe42daee7f77c002d4335744cb8ae330 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 10 Mar 2018 10:14:21 +0200 Subject: [PATCH] refactor nextSeqno out of Publish --- pubsub.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pubsub.go b/pubsub.go index a6394fc..2e33315 100644 --- a/pubsub.go +++ b/pubsub.go @@ -597,10 +597,7 @@ func (p *PubSub) GetTopics() []string { // Publish publishes data under the given topic func (p *PubSub) Publish(topic string, data []byte) error { - seqno := make([]byte, 8) - counter := atomic.AddUint64(&p.counter, 1) - binary.BigEndian.PutUint64(seqno, counter) - + seqno := p.nextSeqno() p.publish <- &Message{ &pb.Message{ Data: data, @@ -612,6 +609,13 @@ func (p *PubSub) Publish(topic string, data []byte) error { return nil } +func (p *PubSub) nextSeqno() []byte { + seqno := make([]byte, 8) + counter := atomic.AddUint64(&p.counter, 1) + binary.BigEndian.PutUint64(seqno, counter) + return seqno +} + type listPeerReq struct { resp chan []peer.ID topic string