refactor nextSeqno out of Publish
This commit is contained in:
parent
e8a91d330a
commit
d6dfe83ebe
12
pubsub.go
12
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user