mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-05-28 11:29:26 +00:00
add an option to configure the Subscription output queue length
This commit is contained in:
parent
c02d4c7179
commit
3c7689d482
10
pubsub.go
10
pubsub.go
@ -1150,6 +1150,16 @@ func (p *PubSub) Subscribe(topic string, opts ...SubOpt) (*Subscription, error)
|
|||||||
return topicHandle.Subscribe(opts...)
|
return topicHandle.Subscribe(opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithBufferSize is a Subscribe option to customize the size of the subscribe output buffer.
|
||||||
|
// The default length is 32 but it can be configured to avoid dropping messages if the consumer is not reading fast
|
||||||
|
// enough.
|
||||||
|
func WithBufferSize(size int) SubOpt {
|
||||||
|
return func(sub *Subscription) error {
|
||||||
|
sub.ch = make(chan *Message, size)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type topicReq struct {
|
type topicReq struct {
|
||||||
resp chan []string
|
resp chan []string
|
||||||
}
|
}
|
||||||
|
|||||||
6
topic.go
6
topic.go
@ -141,7 +141,6 @@ func (t *Topic) Subscribe(opts ...SubOpt) (*Subscription, error) {
|
|||||||
|
|
||||||
sub := &Subscription{
|
sub := &Subscription{
|
||||||
topic: t.topic,
|
topic: t.topic,
|
||||||
ch: make(chan *Message, 32),
|
|
||||||
ctx: t.p.ctx,
|
ctx: t.p.ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +151,11 @@ func (t *Topic) Subscribe(opts ...SubOpt) (*Subscription, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sub.ch == nil {
|
||||||
|
// apply the default size
|
||||||
|
sub.ch = make(chan *Message, 32)
|
||||||
|
}
|
||||||
|
|
||||||
out := make(chan *Subscription, 1)
|
out := make(chan *Subscription, 1)
|
||||||
|
|
||||||
t.p.disc.Discover(sub.topic)
|
t.p.disc.Discover(sub.topic)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user