Fix default options and avoid copying options struct

This commit is contained in:
James Mills 2022-04-04 10:53:30 +10:00
parent a3115435e8
commit 205cac415f
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6
2 changed files with 11 additions and 9 deletions

View File

@ -224,7 +224,7 @@ type MessageBus struct {
// NewMessageBus creates a new message bus with the provided options
func NewMessageBus(opts ...Option) (*MessageBus, error) {
options := DefaultOptions
options := NewDefaultOptions()
for _, opt := range opts {
if err := opt(options); err != nil {
@ -601,7 +601,7 @@ func (mb *MessageBus) Subscribe(id, topic string, opts ...SubscribeOption) chan
log.Debugf("subscriber wants to start from %d", o.Index)
err := q.ForEach(func(item interface{}) error {
if msg, ok := item.(Message); ok && msg.ID >= o.Index {
log.Debugf("found msg #%d", msg.ID)
log.Debugf("found msg %s#%d", msg.Topic.Name, msg.ID)
select {
case ch <- msg:
n++

View File

@ -33,15 +33,17 @@ const (
DefaultNoSync = false
)
var DefaultOptions = &Options{
LogPath: DefaultLogPath,
func NewDefaultOptions() *Options {
return &Options{
LogPath: DefaultLogPath,
BufferLength: DefaultBufferLength,
MaxQueueSize: DefaultMaxQueueSize,
MaxPayloadSize: DefaultMaxPayloadSize,
BufferLength: DefaultBufferLength,
MaxQueueSize: DefaultMaxQueueSize,
MaxPayloadSize: DefaultMaxPayloadSize,
Metrics: DefaultMetrics,
NoSync: DefaultNoSync,
Metrics: DefaultMetrics,
NoSync: DefaultNoSync,
}
}
// Options ...