refactor: extract function to subscribe to topic

This commit is contained in:
Richard Ramos 2021-10-10 18:52:16 -04:00
parent 13aee0b1e0
commit 578b40a44e
1 changed files with 44 additions and 42 deletions

View File

@ -389,7 +389,12 @@ func (node *WakuNode) Subscribe(ctx context.Context, topic *relay.Topic) (*Subsc
node.bcaster.Register(subscription.C)
go func(t relay.Topic) {
go node.subscribeToTopic(t, subscription, sub)
return subscription, nil
}
func (node *WakuNode) subscribeToTopic(t relay.Topic, subscription *Subscription, sub *pubsub.Subscription) {
nextMsgTicker := time.NewTicker(time.Millisecond * 10)
defer nextMsgTicker.Stop()
@ -430,9 +435,6 @@ func (node *WakuNode) Subscribe(ctx context.Context, topic *relay.Topic) (*Subsc
node.bcaster.Submit(envelope)
}
}
}(t)
return subscription, nil
}
// Wrapper around WakuFilter.Subscribe