mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-06 23:03:08 +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...)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
resp chan []string
|
||||
}
|
||||
|
||||
6
topic.go
6
topic.go
@ -141,7 +141,6 @@ func (t *Topic) Subscribe(opts ...SubOpt) (*Subscription, error) {
|
||||
|
||||
sub := &Subscription{
|
||||
topic: t.topic,
|
||||
ch: make(chan *Message, 32),
|
||||
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)
|
||||
|
||||
t.p.disc.Discover(sub.topic)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user